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

This commit is contained in:
Ben
2025-12-30 20:46:02 +00:00
parent fcf13b91fa
commit d152162dbf

View File

@@ -1,6 +1,7 @@
import os import os
import json import json
import logging import logging
from typing import Any
import httpx import httpx
from fastmcp import FastMCP from fastmcp import FastMCP
from starlette.applications import Starlette from starlette.applications import Starlette
@@ -183,7 +184,7 @@ async def list_collection_documents(
@mcp.tool() @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. """Execute a raw Outline API call for any endpoint.
Use the 'outline://api-reference' resource to discover available methods 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: Args:
method: API method name (e.g., 'documents.create', 'users.list') 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: Returns:
JSON string with raw API response JSON string with raw API response
Examples: Examples:
- method='documents.create', params='{"title": "New Doc", "collectionId": "uuid"}' - 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"}' - 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: 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: except json.JSONDecodeError as e:
return json.dumps({"ok": False, "error": f"Invalid JSON params: {str(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) result = await outline_client.call(method, parsed_params)
return json.dumps(result, indent=2) return json.dumps(result, indent=2)