mcp-agent-server
An MCP server that provides agent-powered tools, each using an LLM agent loop to iteratively call FlowMCP schema tools to solve complex problems. It can be mounted as Express middleware and supports A2A protocol for agent-to-agent communication.
README
mcp-agent-server
Version: 2.0.0
MCP Server with agent-powered tools, mountable as Express middleware. Each tool starts an LLM Agent Loop that iteratively calls FlowMCP schema tools to solve problems.
Architecture
flowchart LR
MC[MCP Client] -->|MCP Protocol| B[AgentToolsServer]
A2A[A2A Client] -->|message/send| AD[A2A Adapter]
AD -->|tools/call| B
B --> C[ToolRegistry]
C --> D[AgentLoop]
D -->|OpenRouter| E[LLM]
D -->|callTool| F[ToolClient]
D -->|discover| G[A2A Discovery]
F --> H[FlowMCP Schemas]
H --> I[External APIs]
Quickstart
git clone https://github.com/FlowMCP/mcp-agent-server.git
cd mcp-agent-server
npm i
import express from 'express'
import { AgentToolsServer } from 'mcp-agent-server'
const app = express()
app.use( express.json() )
const { mcp } = await AgentToolsServer.create( {
name: 'My Agent Server',
version: '1.0.0',
routePath: '/mcp',
llm: {
baseURL: 'https://openrouter.ai/api',
apiKey: process.env.OPENROUTER_API_KEY
},
tools: [
{
name: 'defi-research',
description: 'Research DeFi protocols',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string' }
},
required: [ 'query' ]
},
agent: {
systemPrompt: 'You are a DeFi research agent.',
model: 'anthropic/claude-sonnet-4-6',
maxRounds: 10,
maxTokens: 4096
},
toolSources: [
{
type: 'flowmcp',
schemas: [ defilamaSchema, coingeckoSchema ],
serverParams: { DEFILAMA_KEY: process.env.DEFILAMA_KEY }
}
],
execution: {
taskSupport: 'optional'
}
}
]
} )
app.use( mcp.middleware() )
app.listen( 4100 )
Features
- MCP Server with StreamableHTTP transport (session-based)
- LLM Agent Loop with iterative tool calling via Anthropic SDK
- FlowMCP schemas as tool sources (in-process, no external server needed)
- A2A Adapter — optional Agent-to-Agent protocol support (
@a2a-js/sdk) - A2A Discovery — built-in tool to discover other A2A agents
- Agent Card — auto-generated from manifest at
/.well-known/agent.json - Configurable answer schema per tool
- MCP Tasks API for async tool execution
- Composable with
x402-mcp-middlewarefor payment gating - Multiple tool sources per tool via CompositeToolClient
Table of Contents
Methods
AgentToolsServer.create()
Creates a new MCP server instance from configuration.
Method
AgentToolsServer.create( { name, version, routePath, llm, tools, tasks } )
| Key | Type | Description | Required |
|---|---|---|---|
| name | string | Server name for MCP handshake | Yes |
| version | string | Server version | Yes |
| routePath | string | Express route path. Default '/mcp' |
No |
| llm | object | LLM config { baseURL, apiKey } |
Yes |
| tools | array | Array of tool configurations | Yes |
| tasks | object | Task store config { store }. Default InMemoryTaskStore |
No |
Returns
// AgentToolsServer instance
const { mcp } = await AgentToolsServer.create( { /* config */ } )
AgentToolsServer.fromManifest()
Creates a server from a FlowMCP v3.0.0 agent manifest.
Method
AgentToolsServer.fromManifest( { manifest, llm, schemas, serverParams, routePath } )
| Key | Type | Description | Required |
|---|---|---|---|
| manifest | object | Agent manifest (export const agent from agent.mjs) |
Yes |
| llm | object | LLM config { baseURL, apiKey } |
Yes |
| schemas | array | FlowMCP schema objects for the agent's tools | No |
| serverParams | object | API keys for schemas | No |
| routePath | string | Express route path. Default '/mcp' |
No |
Example
import { agent } from './agent.mjs'
const { mcp } = await AgentToolsServer.fromManifest( {
manifest: agent,
llm: {
baseURL: 'https://openrouter.ai/api',
apiKey: process.env.OPENROUTER_API_KEY
},
schemas: [ etherscanSchema, defilamaSchema ],
serverParams: { ETHERSCAN_API_KEY: process.env.ETHERSCAN_API_KEY }
} )
.middleware()
Returns an Express middleware function that handles MCP protocol requests (POST/GET/DELETE) on the configured route path.
Method
mcp.middleware()
Returns
// Express middleware function (req, res, next) => Promise<void>
app.use( mcp.middleware() )
.listToolDefinitions()
Returns all registered tools in MCP ListTools format.
Method
mcp.listToolDefinitions()
Returns
const { tools } = mcp.listToolDefinitions()
// tools: [ { name, description, inputSchema, execution? } ]
| Key | Type | Description |
|---|---|---|
| tools | array | Array of tool definitions in MCP format |
Tool Configuration
Each tool in the tools array has the following structure:
| Key | Type | Description | Required |
|---|---|---|---|
| name | string | Tool name (used in MCP protocol) | Yes |
| description | string | Tool description | Yes |
| inputSchema | object | JSON Schema for tool input | Yes |
| agent | object | Agent configuration (see below) | Yes |
| toolSources | array | Array of tool source configs (see below) | Yes |
| execution | object | { taskSupport: 'optional' | 'required' } |
No |
Agent Configuration
| Key | Type | Description | Required |
|---|---|---|---|
| systemPrompt | string | System prompt for the LLM | Yes |
| model | string | LLM model ID (e.g. 'anthropic/claude-sonnet-4-6') |
Yes |
| maxRounds | number | Maximum agent iterations. Default 10 |
No |
| maxTokens | number | Max completion tokens. Default 4096 |
No |
| answerSchema | object | Custom JSON Schema for submit_answer tool |
No |
Tool Sources
Each entry in toolSources defines where the agent gets its tools from:
| Key | Type | Description | Required |
|---|---|---|---|
| type | string | Source type. Currently 'flowmcp' |
Yes |
| schemas | array | FlowMCP schema objects | Yes |
| serverParams | object | Environment variables / API keys for schemas | No |
A2A Adapter
Optional Agent-to-Agent protocol support. Import separately:
import { AgentToolsServer } from 'mcp-agent-server'
import { A2AAdapter } from 'mcp-agent-server/a2a'
const { mcp } = await AgentToolsServer.fromManifest( { manifest, llm: { ... } } )
app.use( mcp.middleware() )
// A2A (optional)
const a2a = A2AAdapter.from( { mcp, manifest, serverUrl: 'https://my-agent.com' } )
app.use( '/.well-known/agent.json', a2a.agentCardMiddleware() )
app.use( '/a2a/v1', a2a.handler() )
This exposes three endpoints:
| Endpoint | Protocol | Purpose |
|---|---|---|
POST /mcp |
MCP | Tool calls from MCP clients (Claude Desktop, Cursor) |
GET /.well-known/agent.json |
A2A | Agent discovery (Agent Card) |
POST /a2a/v1 |
A2A | Agent-to-agent communication (message/send) |
The A2A adapter translates message/send into MCP tools/call — no separate agent loop.
A2A Discovery
The agent loop includes an optional discover_agent tool that fetches Agent Cards from other A2A agents:
const { mcp } = await AgentToolsServer.fromManifest( {
manifest,
llm: { ... },
discovery: true // Enables discover_agent tool
} )
Composition with x402
No code coupling. Pure Express middleware ordering:
import express from 'express'
import { X402Middleware } from 'x402-mcp-middleware/v2'
import { AgentToolsServer } from 'mcp-agent-server'
const app = express()
app.use( express.json() )
// 1. Payment gate (optional)
const x402 = await X402Middleware.create( { /* config */ } )
app.use( x402.mcp() )
// 2. Agent MCP Server
const { mcp } = await AgentToolsServer.create( { /* config */ } )
app.use( mcp.middleware() )
app.listen( 4100 )
Documentation
Full FlowMCP documentation at flowmcp.github.io. See the Agent Server page for integration guides.
License
MIT
Contributing
PRs are welcome. Please open an issue first to discuss proposed changes.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。