Skip to content

Commit 136a847

Browse files
authored
Feat/fast mcp settings (#361)
* Support settings dict for FastMCP server * Fix settings spread * Just use kwargs instead of settings arg
1 parent 0c9484b commit 136a847

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

examples/mcp_agent_server/asyncio/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ https://github.com/user-attachments/assets/f651af86-222d-4df0-8241-616414df66e4
1212

1313
- Creating workflows with the `Workflow` base class
1414
- Registering workflows with an `MCPApp`
15-
- Exposing workflows as MCP tools using `create_mcp_server_for_app`
15+
- Exposing workflows as MCP tools using `create_mcp_server_for_app`, optionally using custom FastMCP settings
1616
- Connecting to an MCP server using `gen_client`
1717
- Running workflows remotely and monitoring their status
1818

@@ -93,11 +93,18 @@ You can also run the server and client separately:
9393

9494
```bash
9595
uv run basic_agent_server.py
96+
97+
# Optionally, run with the example custom FastMCP settings
98+
uv run basic_agent_server.py --custom-fastmcp-settings
9699
```
97100

98101
2. In another terminal, run the client:
102+
99103
```bash
100104
uv run client.py
105+
106+
# Optionally, run with the example custom FastMCP settings
107+
uv run client.py --custom-fastmcp-settings
101108
```
102109

103110
## MCP Clients

examples/mcp_agent_server/asyncio/basic_agent_server.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
3. Declarative agent configuration using FastMCPApp decorators
88
"""
99

10+
import argparse
1011
import asyncio
1112
import os
1213
import logging
@@ -169,6 +170,15 @@ async def run(self, input: str) -> WorkflowResult[str]:
169170

170171

171172
async def main():
173+
parser = argparse.ArgumentParser()
174+
parser.add_argument(
175+
"--custom-fastmcp-settings",
176+
action="store_true",
177+
help="Enable custom FastMCP settings for the server",
178+
)
179+
args = parser.parse_args()
180+
use_custom_fastmcp_settings = args.custom_fastmcp_settings
181+
172182
async with app.run() as agent_app:
173183
# Add the current directory to the filesystem server's args if needed
174184
context = agent_app.context
@@ -182,8 +192,15 @@ async def main():
182192
for workflow_id in agent_app.workflows:
183193
logger.info(f" - {workflow_id}")
184194

185-
# Create the MCP server that exposes both workflows and agent configurations
186-
mcp_server = create_mcp_server_for_app(agent_app)
195+
# Create the MCP server that exposes both workflows and agent configurations,
196+
# optionally using custom FastMCP settings
197+
fast_mcp_settings = (
198+
{"host": "localhost", "port": 8001, "debug": True, "log_level": "DEBUG"}
199+
if use_custom_fastmcp_settings
200+
else None
201+
)
202+
mcp_server = create_mcp_server_for_app(agent_app, **(fast_mcp_settings or {}))
203+
logger.info(f"MCP Server settings: {mcp_server.settings}")
187204

188205
# Add custom tool to get token usage for a workflow
189206
@mcp_server.tool(

examples/mcp_agent_server/asyncio/client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import asyncio
23
import json
34
import time
@@ -11,6 +12,15 @@
1112

1213

1314
async def main():
15+
parser = argparse.ArgumentParser()
16+
parser.add_argument(
17+
"--custom-fastmcp-settings",
18+
action="store_true",
19+
help="Enable custom FastMCP settings for the server",
20+
)
21+
args = parser.parse_args()
22+
use_custom_fastmcp_settings = args.custom_fastmcp_settings
23+
1424
# Create MCPApp to get the server registry
1525
app = MCPApp(name="workflow_mcp_client")
1626
async with app.run() as client_app:
@@ -21,11 +31,17 @@ async def main():
2131
logger.info("Connecting to workflow server...")
2232

2333
# Override the server configuration to point to our local script
34+
run_server_args = ["run", "basic_agent_server.py"]
35+
if use_custom_fastmcp_settings:
36+
logger.info("Using custom FastMCP settings for the server.")
37+
run_server_args += ["--custom-fastmcp-settings"]
38+
else:
39+
logger.info("Using default FastMCP settings for the server.")
2440
context.server_registry.registry["basic_agent_server"] = MCPServerSettings(
2541
name="basic_agent_server",
2642
description="Local workflow server running the basic agent example",
2743
command="uv",
28-
args=["run", "basic_agent_server.py"],
44+
args=run_server_args,
2945
)
3046

3147
# Connect to the workflow server

src/mcp_agent/server/app_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ def workflow_registry(self) -> WorkflowRegistry:
8181
return self.context.workflow_registry
8282

8383

84-
def create_mcp_server_for_app(app: MCPApp) -> FastMCP:
84+
def create_mcp_server_for_app(app: MCPApp, **kwargs: Any) -> FastMCP:
8585
"""
8686
Create an MCP server for a given MCPApp instance.
8787
8888
Args:
8989
app: The MCPApp instance to create a server for
90+
kwargs: Optional FastMCP settings to configure the server.
9091
9192
Returns:
9293
A configured FastMCP server instance
@@ -119,6 +120,7 @@ async def app_specific_lifespan(mcp: FastMCP) -> AsyncIterator[ServerContext]:
119120
# or use the MCPApp's description if available.
120121
instructions=f"MCP server exposing {app.name} workflows and agents. Description: {app.description}",
121122
lifespan=app_specific_lifespan,
123+
**kwargs,
122124
)
123125

124126
# region Workflow Tools

0 commit comments

Comments
 (0)