fastmcp
fastmcp copied to clipboard
Added feature : Load MCP server using config
The current Client supports loading server from ClientTransport , FastMCP server , script path, URL . It does not support config dictionary to add a server which is a standard way in many clients . I have added this feature for adding a single server through config dictionary.
Example client.py
from fastmcp import Client
import asyncio
config = {
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time", "--local-timezone=Asia/Kolkata"]
}
}
}
client = Client(config)
print(client.transport.args)
async def main():
async with client:
print(f"Client connected: {client.is_connected()}")
tools = await client.list_tools()
print(f"Available tools: {[tool.name for tool in tools]}")
if any(tool.name == "get_current_time" for tool in tools):
result = await client.call_tool("get_current_time", {"timezone": "Asia/Kolkata"})
print(f"Time result: {result[0].text}")
print(f"Client connected: {client.is_connected()}")
if __name__ == "__main__":
asyncio.run(main())
Output :
['mcp-server-time', '--local-timezone=Asia/Kolkata']
Client connected: True
Available tools: ['get_current_time', 'convert_time']
Time result: {
"timezone": "Asia/Kolkata",
"datetime": "2025-04-26T02:11:10+05:30",
"is_dst": false
}
Client connected: False
Thanks! Great idea. I think this just needs some tests to ensure it works, nothing complex.
Hey @jlowin I have run a few example server tests on my local. Please let me know how to be more comprehensive about it