Day 23
API Integration MCP
Build MCPs for your internal APIs and third-party services.
0 / 5 tasks
API MCP pattern
python
# Pattern: wrap any REST API as MCP tools
import httpx
from mcp.server import Server
from mcp.types import Tool, TextContent
app = Server("jira-mcp")
BASE_URL = "https://yourorg.atlassian.net/rest/api/3"
HEADERS = {"Authorization": "Bearer YOUR_TOKEN"}
@app.list_tools()
async def list_tools():
return [
Tool(name="get_issue", description="Get a Jira issue by key",
inputSchema={"type": "object", "properties": {"key": {"type": "string"}}, "required": ["key"]}),
Tool(name="list_sprint_issues", description="List all issues in current sprint",
inputSchema={"type": "object", "properties": {"board_id": {"type": "integer"}}, "required": ["board_id"]}),
]
@app.call_tool()
async def call_tool(name: str, arguments: dict):
async with httpx.AsyncClient() as client:
if name == "get_issue":
r = await client.get(f"{BASE_URL}/issue/{arguments['key']}", headers=HEADERS)
return [TextContent(type="text", text=r.text)]