Skip to content

Commit 31fdf4c

Browse files
add bootstrap mcp
1 parent 81810fc commit 31fdf4c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

mp_api/mcp/mp_mcp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from __future__ import annotations
33

44
from typing import Any
5+
from urllib.parse import urljoin
56

7+
import httpx
68
from fastmcp import FastMCP
79
from pydantic import BaseModel, Field, PrivateAttr
810

@@ -34,3 +36,17 @@ def mcp(self, **kwargs) -> FastMCP:
3436
mcp.tool(getattr(mcp_tools, attr))
3537

3638
return mcp
39+
40+
def bootstrap_mcp(self, **kwargs) -> FastMCP:
41+
"""Bootstrap an MP API MCP only from the OpenAPI spec."""
42+
return FastMCP.from_openapi(
43+
openapi_spec=httpx.get(
44+
urljoin(self.client.endpoint, "openapi.json")
45+
).json(),
46+
client=httpx.AsyncClient(
47+
base_url=self.client.endpoint,
48+
headers={"x-api-key": self.client.api_key},
49+
),
50+
name=self.name,
51+
**kwargs,
52+
)

0 commit comments

Comments
 (0)