malek-messaoudii commited on
Commit
bd8a3b8
·
1 Parent(s): c508ed0

feat: Enhance ToolCallRequest and ToolCallResponse models with detailed examples and descriptions for improved clarity and usability in MCP tool calls.

Browse files
Files changed (2) hide show
  1. models/mcp_models.py +34 -6
  2. routes/mcp_routes.py +60 -1
models/mcp_models.py CHANGED
@@ -3,15 +3,43 @@ from typing import Any, Dict, List, Optional
3
 
4
  class ToolCallRequest(BaseModel):
5
  """Request for calling an MCP tool"""
6
- tool_name: str
7
- arguments: Dict[str, Any] = {}
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  class ToolCallResponse(BaseModel):
10
  """Response from MCP tool call"""
11
- success: bool
12
- result: Optional[Dict[str, Any]] = None
13
- error: Optional[str] = None
14
- tool_name: str
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Response models for individual MCP tools
17
  class DetectStanceResponse(BaseModel):
 
3
 
4
  class ToolCallRequest(BaseModel):
5
  """Request for calling an MCP tool"""
6
+ model_config = ConfigDict(
7
+ json_schema_extra={
8
+ "example": {
9
+ "tool_name": "detect_stance",
10
+ "arguments": {
11
+ "topic": "Climate change is real",
12
+ "argument": "Rising global temperatures prove it"
13
+ }
14
+ }
15
+ }
16
+ )
17
+
18
+ tool_name: str = Field(..., description="Name of the MCP tool to call (e.g., 'detect_stance', 'match_keypoint_argument', 'transcribe_audio', 'generate_speech', 'generate_argument')")
19
+ arguments: Dict[str, Any] = Field(default_factory=dict, description="Arguments for the tool (varies by tool)")
20
 
21
  class ToolCallResponse(BaseModel):
22
  """Response from MCP tool call"""
23
+ model_config = ConfigDict(
24
+ json_schema_extra={
25
+ "example": {
26
+ "success": True,
27
+ "result": {
28
+ "predicted_stance": "PRO",
29
+ "confidence": 0.9598,
30
+ "probability_con": 0.0402,
31
+ "probability_pro": 0.9598
32
+ },
33
+ "error": None,
34
+ "tool_name": "detect_stance"
35
+ }
36
+ }
37
+ )
38
+
39
+ success: bool = Field(..., description="Whether the tool call was successful")
40
+ result: Optional[Dict[str, Any]] = Field(None, description="Result from the tool call")
41
+ error: Optional[str] = Field(None, description="Error message if the call failed")
42
+ tool_name: str = Field(..., description="Name of the tool that was called")
43
 
44
  # Response models for individual MCP tools
45
  class DetectStanceResponse(BaseModel):
routes/mcp_routes.py CHANGED
@@ -188,7 +188,66 @@ async def list_mcp_tools():
188
 
189
  @router.post("/tools/call", response_model=ToolCallResponse, summary="Appeler un outil MCP")
190
  async def call_mcp_tool(request: ToolCallRequest):
191
- """Appelle un outil MCP par son nom avec des arguments"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  try:
193
  result = await mcp_server.call_tool(request.tool_name, request.arguments)
194
  # Gérer différents types de retours MCP
 
188
 
189
  @router.post("/tools/call", response_model=ToolCallResponse, summary="Appeler un outil MCP")
190
  async def call_mcp_tool(request: ToolCallRequest):
191
+ """
192
+ Appelle un outil MCP par son nom avec des arguments
193
+
194
+ **Exemples d'utilisation:**
195
+
196
+ 1. **detect_stance** - Détecter la stance d'un argument:
197
+ ```json
198
+ {
199
+ "tool_name": "detect_stance",
200
+ "arguments": {
201
+ "topic": "Climate change is real",
202
+ "argument": "Rising global temperatures prove it"
203
+ }
204
+ }
205
+ ```
206
+
207
+ 2. **match_keypoint_argument** - Matcher un argument avec un keypoint:
208
+ ```json
209
+ {
210
+ "tool_name": "match_keypoint_argument",
211
+ "arguments": {
212
+ "argument": "Renewable energy reduces emissions",
213
+ "key_point": "Environmental benefits"
214
+ }
215
+ }
216
+ ```
217
+
218
+ 3. **generate_argument** - Générer un argument:
219
+ ```json
220
+ {
221
+ "tool_name": "generate_argument",
222
+ "arguments": {
223
+ "topic": "Assisted suicide should be legal",
224
+ "position": "positive"
225
+ }
226
+ }
227
+ ```
228
+
229
+ 4. **transcribe_audio** - Transcrire un audio:
230
+ ```json
231
+ {
232
+ "tool_name": "transcribe_audio",
233
+ "arguments": {
234
+ "audio_path": "/path/to/audio.wav"
235
+ }
236
+ }
237
+ ```
238
+
239
+ 5. **generate_speech** - Générer de la parole:
240
+ ```json
241
+ {
242
+ "tool_name": "generate_speech",
243
+ "arguments": {
244
+ "text": "Hello, this is a test",
245
+ "voice": "Aaliyah-PlayAI",
246
+ "format": "wav"
247
+ }
248
+ }
249
+ ```
250
+ """
251
  try:
252
  result = await mcp_server.call_tool(request.tool_name, request.arguments)
253
  # Gérer différents types de retours MCP