mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 04:24:17 +02:00
Use ergonomic provider initialization pattern (#2675)
Updates examples and convenience methods to pass providers directly to FastMCP's __init__ instead of calling add_provider() after instantiation.
This commit is contained in:
parent
820b69aa2e
commit
bca310cdde
4 changed files with 7 additions and 20 deletions
|
|
@ -101,10 +101,8 @@ class SQLiteToolProvider(Provider):
|
|||
)
|
||||
|
||||
|
||||
mcp = FastMCP("DynamicToolsServer")
|
||||
|
||||
provider = SQLiteToolProvider(db_path=str(DB_PATH))
|
||||
mcp.add_provider(provider)
|
||||
mcp = FastMCP("DynamicToolsServer", providers=[provider])
|
||||
|
||||
|
||||
@mcp.tool
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ This class is deprecated. Use FastMCP with OpenAPIProvider instead:
|
|||
|
||||
client = httpx.AsyncClient(base_url="https://api.example.com")
|
||||
provider = OpenAPIProvider(openapi_spec=spec, client=client)
|
||||
|
||||
mcp = FastMCP("My API Server")
|
||||
mcp.add_provider(provider)
|
||||
mcp = FastMCP("My API Server", providers=[provider])
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
|
@ -55,9 +53,7 @@ class FastMCPOpenAPI(FastMCP):
|
|||
|
||||
client = httpx.AsyncClient(base_url="https://api.example.com")
|
||||
provider = OpenAPIProvider(openapi_spec=spec, client=client)
|
||||
|
||||
mcp = FastMCP("API Server")
|
||||
mcp.add_provider(provider)
|
||||
mcp = FastMCP("API Server", providers=[provider])
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
@ -94,8 +90,7 @@ class FastMCPOpenAPI(FastMCP):
|
|||
warnings.warn(
|
||||
"FastMCPOpenAPI is deprecated. Use FastMCP with OpenAPIProvider instead:\n"
|
||||
" provider = OpenAPIProvider(openapi_spec=spec, client=client)\n"
|
||||
" mcp = FastMCP('name')\n"
|
||||
" mcp.add_provider(provider)",
|
||||
" mcp = FastMCP('name', providers=[provider])",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ Example:
|
|||
|
||||
client = httpx.AsyncClient(base_url="https://api.example.com")
|
||||
provider = OpenAPIProvider(openapi_spec=spec, client=client)
|
||||
|
||||
mcp = FastMCP("API Server")
|
||||
mcp.add_provider(provider)
|
||||
mcp = FastMCP("API Server", providers=[provider])
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -2788,9 +2788,7 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
tags=tags,
|
||||
timeout=timeout,
|
||||
)
|
||||
server = cls(name=name, **settings)
|
||||
server.add_provider(provider)
|
||||
return server
|
||||
return cls(name=name, providers=[provider], **settings)
|
||||
|
||||
@classmethod
|
||||
def from_fastapi(
|
||||
|
|
@ -2847,9 +2845,7 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
tags=tags,
|
||||
timeout=timeout,
|
||||
)
|
||||
server = cls(name=server_name, **settings)
|
||||
server.add_provider(provider)
|
||||
return server
|
||||
return cls(name=server_name, providers=[provider], **settings)
|
||||
|
||||
@classmethod
|
||||
def as_proxy(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue