Fix params type: accept Any (string, dict, or None) for flexibility
All checks were successful
Build and Push Outline MCP Docker Image / build (push) Successful in 7s
All checks were successful
Build and Push Outline MCP Docker Image / build (push) Successful in 7s
This commit is contained in:
22
server.py
22
server.py
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
import httpx
|
||||
from fastmcp import FastMCP
|
||||
from starlette.applications import Starlette
|
||||
@@ -183,7 +184,7 @@ async def list_collection_documents(
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def outline_api_call(method: str, params: str = "") -> str:
|
||||
async def outline_api_call(method: str, params: Any = None) -> str:
|
||||
"""Execute a raw Outline API call for any endpoint.
|
||||
|
||||
Use the 'outline://api-reference' resource to discover available methods
|
||||
@@ -191,20 +192,33 @@ async def outline_api_call(method: str, params: str = "") -> str:
|
||||
|
||||
Args:
|
||||
method: API method name (e.g., 'documents.create', 'users.list')
|
||||
params: JSON string of parameters to send in request body
|
||||
params: Parameters as JSON string or dict (optional)
|
||||
|
||||
Returns:
|
||||
JSON string with raw API response
|
||||
|
||||
Examples:
|
||||
- method='documents.create', params='{"title": "New Doc", "collectionId": "uuid"}'
|
||||
- method='users.list', params='{"limit": 10}'
|
||||
- method='users.list', params={"limit": 10}
|
||||
- method='documents.delete', params='{"id": "document-uuid"}'
|
||||
"""
|
||||
# Handle params being string, dict, or None/empty
|
||||
if params is None or params == "" or params == {}:
|
||||
parsed_params = {}
|
||||
elif isinstance(params, dict):
|
||||
parsed_params = params
|
||||
elif isinstance(params, str):
|
||||
try:
|
||||
parsed_params = json.loads(params) if params and params.strip() else {}
|
||||
parsed_params = json.loads(params) if params.strip() else {}
|
||||
except json.JSONDecodeError as e:
|
||||
return json.dumps({"ok": False, "error": f"Invalid JSON params: {str(e)}"})
|
||||
else:
|
||||
return json.dumps(
|
||||
{
|
||||
"ok": False,
|
||||
"error": f"params must be string or dict, got {type(params).__name__}",
|
||||
}
|
||||
)
|
||||
|
||||
result = await outline_client.call(method, parsed_params)
|
||||
return json.dumps(result, indent=2)
|
||||
|
||||
Reference in New Issue
Block a user