mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 21:14:17 +02:00
Simplify proxy load
This commit is contained in:
parent
d8779d2c2e
commit
ed57b4cd42
2 changed files with 9 additions and 10 deletions
|
|
@ -292,10 +292,10 @@ def run(
|
|||
"""Run an MCP server or connect to a remote one.
|
||||
|
||||
The server can be specified in four ways:
|
||||
1. Module approach: server.py - runs the module directly, looking for an object named 'mcp', 'server', or 'app'
|
||||
2. Import approach: server.py:app - imports and runs the specified server object
|
||||
3. URL approach: http://server-url - connects to a remote server and creates a proxy
|
||||
4. MCPConfig file: mcp.json - runs as a proxy server for the MCP Servers in the MCPConfig file
|
||||
1. Module approach: "server.py" - runs the module directly, looking for an object named 'mcp', 'server', or 'app'
|
||||
2. Import approach: "server.py:app" - imports and runs the specified server object
|
||||
3. URL approach: "http://server-url" - connects to a remote server and creates a proxy
|
||||
4. MCPConfig file: "mcp.json" - runs as a proxy server for the MCP Servers in the MCPConfig file
|
||||
|
||||
Server arguments can be passed after -- :
|
||||
fastmcp run server.py -- --config config.json --debug
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
"""FastMCP run command implementation with enhanced type hints."""
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
|
@ -146,13 +147,11 @@ def create_client_server(url: str) -> Any:
|
|||
def create_mcp_config_server(mcp_config_path: Path) -> FastMCP[None]:
|
||||
"""Create a FastMCP server from a MCPConfig."""
|
||||
from fastmcp import FastMCP
|
||||
from fastmcp.client import Client
|
||||
from fastmcp.client.transports import MCPConfigTransport
|
||||
from fastmcp.mcp_config import MCPConfig
|
||||
|
||||
mcp_config = MCPConfig.from_file(mcp_config_path)
|
||||
client = Client[MCPConfigTransport](mcp_config)
|
||||
server = FastMCP.as_proxy(client)
|
||||
with mcp_config_path.open() as src:
|
||||
mcp_config = json.load(src)
|
||||
|
||||
server = FastMCP.as_proxy(mcp_config)
|
||||
return server
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue