MC

MCP Server: Composable Agents for Model Context Protocol

Build composable agents with MCP server, a simple framework using the Model Context Protocol by LastMile AI to prototype and deploy.

Quick Install
pip install mcp-agent

Overview

The MCP Server implements the Model Context Protocol (MCP) by LastMile AI and provides a lightweight framework for building composable agents. It abstracts context management, tool registration, and agent orchestration so you can prototype multi-tool workflows and deploy agents that combine models, tools, and external resources. The server focuses on modularity: agents are defined as pipelines of tools and model calls driven by MCP messages, enabling reusable components and predictable data flow.

For developers, MCP Server reduces boilerplate when connecting language models to tools (search, code execution, data stores, etc.). It offers an API surface for registering tools, creating agent definitions, and invoking agents with structured inputs. This makes it easier to iterate on agent behaviors and switch components without rewriting glue logic.

Features

  • Implements Model Context Protocol primitives for structured context exchange
  • Registerable tools (HTTP-backed or local handlers) that agents can call
  • Agent definitions as composable pipelines of model prompts and tool calls
  • REST API for managing tools, agents, and executions
  • Local development mode with hot-reload for fast iteration
  • Docker support for reproducible deployment
  • Examples and starter templates for common agent patterns

Installation / Configuration

Prerequisites: Node.js 18+ or Docker.

Clone and run locally:

# clone repository
git clone https://github.com/lastmile-ai/mcp-agent.git
cd mcp-agent

# install dependencies
npm install

# start in development mode
npm run dev

Start with Docker:

# build image
docker build -t mcp-server .

# run container (default port 8080)
docker run -p 8080:8080 \
  -e PORT=8080 \
  -e MCP_API_KEY=your_api_key \
  mcp-server

Configuration can be provided via environment variables or a config file (JSON/YAML). Example .env-style variables:

PORT=8080
LOG_LEVEL=info
MCP_API_KEY=your_api_key
TOOLS_DIR=./tools
AGENTS_DIR=./agents

Agent/tool definitions live in a directory specified by TOOLS_DIR/AGENTS_DIR and are automatically loaded on startup in development mode.

Available Resources

  • GitHub repository: https://github.com/lastmile-ai/mcp-agent
  • Example agents and tools are included in the repo under /examples
  • API docs (auto-generated) are available at /docs when the server runs
  • Starter templates: examples/simple-agent, examples/web-search-agent

Example API (typical endpoints)

The exact routes may vary depending on configuration; below are common endpoints you will use.

EndpointMethodPurpose
/api/toolsGET / POSTlist and register tools
/api/agentsGET / POSTlist and create agent definitions
/api/agents/{id}/invokePOSTexecute an agent with input
/api/mcpPOSTraw MCP messages endpoint (advanced)

Example: register a simple HTTP tool

curl -X POST http://localhost:8080/api/tools \
  -H "Authorization: Bearer $MCP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "web_search",
    "type": "http",
    "config": {
      "url": "https://api.example.com/search?q={{query}}",
      "method": "GET"
    }
  }'

Create an agent that uses the tool and a model:

curl -X POST http://localhost:8080/api/agents \
  -H "Authorization: Bearer $MCP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "researcher",
    "steps": [
      { "type": "model", "model": "gpt-4", "prompt": "Summarize the query: {{input.query}}" },
      { "type": "tool", "toolId": "web_search", "inputFrom": "previous.output" },
      { "type": "model", "model": "gpt-4", "prompt": "Create an answer using: {{steps.*.output}}" }
    ]
  }'

Invoke the agent:

curl -X POST http://localhost:8080/api/agents/researcher/invoke \
  -H "Authorization: Bearer $MCP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"latest research on MCP"}'

Responses follow MCP-style structured messages so you can trace how context moved between steps.

Use Cases

  • Rapid prototyping: Combine a model prompt with a web-search tool and a code-execution tool to build a research assistant in hours.
  • Reusable tool chains: Define tools for common tasks (HTTP API wrappers, DB lookups, Python execution) and reuse them across agents.
  • Deterministic testing: Because agent steps are declarative, you can unit-test each step and replay MCP messages for reproducible behavior.
  • Deployment-ready agents: Use Docker mode to containerize an agent and operate it behind a load balancer or job queue.
  • Observability and auditing: Structured MCP messages make it straightforward to log inputs/outputs at each step for compliance or debugging.

Best Practices

  • Keep tools small and focused: each tool should do one job (search, execute code, access a DB).
  • Use environment variables for secrets and API keys rather than embedding them in agent definitions.
  • Start with local dev and example agents to learn flow before deploying to production.
  • Write unit tests against the agent steps by mocking tool responses and model outputs.

For full reference and example agents, see the repository: https://github.com/lastmile-ai/mcp-agent.