-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (33 loc) · 1.14 KB
/
main.py
File metadata and controls
41 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List, Dict, Optional
from MCP_servers.mcp_response_generator import generate_response_from_mcp
import asyncio
app = FastAPI()
class ChatHistoryItem(BaseModel):
user_id: int
role: str
message: str
send_time: str
class Config:
allow_population_by_field_name = True
alias_generator = lambda field: ''.join(
word if i == 0 else word.capitalize() for i, word in enumerate(field.split('_'))
)
class MCPPrompt(BaseModel):
template: str
inputs: Dict[str, str]
history: Optional[List[ChatHistoryItem]] = []
class MCPRequest(BaseModel):
prompt: MCPPrompt
resources: Optional[Dict[str, List[str]]] = {}
tools: Optional[List[dict]] = []
@app.post("/mcp/query")
# This endpoint supports both camelCase and snake_case formats in incoming JSON.
async def handle_mcp_query(mcp_request: MCPRequest):
result = await asyncio.to_thread(generate_response_from_mcp, mcp_request.dict())
return {
"role": "assistant",
"userId": mcp_request.prompt.inputs.get("user_id"),
"message": result
}