Skip to content

Commit e14d617

Browse files
authored
v0.1.8
* feat: add customizable context parameter description for tools Allow users to customize the description text for the context parameter that's added to MCP tools. Defaults to the standard description but can be overridden via custom_context_description in MCPCatOptions. * v0.1.8
1 parent 0974792 commit e14d617

File tree

8 files changed

+32
-19
lines changed

8 files changed

+32
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcpcat"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "Analytics Tool for MCP Servers - provides insights into MCP tool usage patterns"
55
authors = [
66
{ name = "MCPCat", email = "support@mcpcat.io" },

src/mcpcat/modules/compatibility.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,39 @@ def call_tool(self, name: str, arguments: dict) -> Any:
3030

3131
def is_community_fastmcp_server(server: Any) -> bool:
3232
"""Check if the server is a community FastMCP instance.
33-
33+
3434
Community FastMCP comes from the 'fastmcp' package.
35+
Supports FastMCP subclasses like FastMCPOpenAPI, FastMCPProxy, etc.
3536
"""
3637
# Check by class name and module
3738
class_name = server.__class__.__name__
3839
module_name = server.__class__.__module__
39-
40-
# Community FastMCP has class name 'FastMCP' and module starts with 'fastmcp'
40+
41+
# Community FastMCP has class name containing 'FastMCP' and module starts with 'fastmcp'
42+
# This supports FastMCPOpenAPI, FastMCPProxy, and other subclasses
4143
return (
42-
class_name == "FastMCP" and
44+
"FastMCP" in class_name and
4345
module_name.startswith("fastmcp") and
44-
hasattr(server, "_mcp_server") and
46+
hasattr(server, "_mcp_server") and
4547
hasattr(server, "_tool_manager")
4648
)
4749

4850
def is_official_fastmcp_server(server: Any) -> bool:
4951
"""Check if the server is an official FastMCP instance.
50-
52+
5153
Official FastMCP comes from the 'mcp.server.fastmcp' module.
54+
Supports FastMCP subclasses like FastMCPOpenAPI, FastMCPProxy, etc.
5255
"""
5356
# Check by class name and module
5457
class_name = server.__class__.__name__
5558
module_name = server.__class__.__module__
56-
57-
# Official FastMCP has class name 'FastMCP' and module 'mcp.server.fastmcp'
59+
60+
# Official FastMCP has class name containing 'FastMCP' and module 'mcp.server.fastmcp'
61+
# This supports FastMCPOpenAPI, FastMCPProxy, and other subclasses
5862
return (
59-
class_name == "FastMCP" and
63+
"FastMCP" in class_name and
6064
module_name.startswith("mcp.server.fastmcp") and
61-
hasattr(server, "_mcp_server") and
65+
hasattr(server, "_mcp_server") and
6266
hasattr(server, "_tool_manager")
6367
)
6468

src/mcpcat/modules/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
SESSION_ID_PREFIX = "ses"
44
EVENT_ID_PREFIX = "evt"
55
MCPCAT_API_URL = "https://api.mcpcat.io" # Default API URL for MCPCat events
6+
DEFAULT_CONTEXT_DESCRIPTION = "Describe why you are calling this tool and how it fits into your overall task"

src/mcpcat/modules/context_parameters.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from typing import Any
44

55

6-
def add_context_parameter_to_tools(tools: list[dict[str, Any]]) -> list[dict[str, Any]]:
6+
def add_context_parameter_to_tools(
7+
tools: list[dict[str, Any]], custom_context_description: str
8+
) -> list[dict[str, Any]]:
79
"""Add context parameter to tool schemas."""
810
modified_tools = []
911

@@ -13,15 +15,17 @@ def add_context_parameter_to_tools(tools: list[dict[str, Any]]) -> list[dict[str
1315

1416
if "inputSchema" in modified_tool:
1517
modified_tool["inputSchema"] = add_context_parameter_to_schema(
16-
modified_tool["inputSchema"]
18+
modified_tool["inputSchema"], custom_context_description
1719
)
1820

1921
modified_tools.append(modified_tool)
2022

2123
return modified_tools
2224

2325

24-
def add_context_parameter_to_schema(schema: dict[str, Any]) -> dict[str, Any]:
26+
def add_context_parameter_to_schema(
27+
schema: dict[str, Any], custom_context_description: str
28+
) -> dict[str, Any]:
2529
"""Add context parameter to a JSON schema."""
2630
# Create a copy to avoid modifying original
2731
modified_schema = schema.copy()
@@ -36,7 +40,7 @@ def add_context_parameter_to_schema(schema: dict[str, Any]) -> dict[str, Any]:
3640
# Add context parameter
3741
modified_schema["properties"]["context"] = {
3842
"type": "string",
39-
"description": "Describe why you are calling this tool and how it fits into your overall task",
43+
"description": custom_context_description,
4044
}
4145

4246
# Add to required fields

src/mcpcat/modules/overrides/community/tool_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async def get_more_tools(context: str | None = "") -> str:
7979
def patch_existing_tools(server: FastMCP) -> None:
8080
"""Modify existing tools to include the context parameter."""
8181
try:
82+
data = get_server_tracking_data(server._mcp_server)
8283
tool_manager = server._tool_manager
8384
if not hasattr(tool_manager, "_tools"):
8485
write_to_log("No _tools dictionary found on tool manager")
@@ -102,7 +103,7 @@ def patch_existing_tools(server: FastMCP) -> None:
102103
# Always overwrite the context property with MCPCat's version
103104
tool.parameters["properties"]["context"] = {
104105
"type": "string",
105-
"description": "Describe why you are calling this tool and how it fits into your overall task"
106+
"description": data.options.custom_context_description,
106107
}
107108

108109
# Add to required array
@@ -168,7 +169,7 @@ def patched_add_tool(tool: Any) -> Any:
168169
# Always overwrite the context property with MCPCat's version
169170
tool.parameters["properties"]["context"] = {
170171
"type": "string",
171-
"description": "Describe why you are calling this tool and how it fits into your overall task"
172+
"description": data.options.custom_context_description
172173
}
173174

174175
# Add to required array

src/mcpcat/modules/overrides/mcp_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def wrapped_list_tools_handler(request: ListToolsRequest) -> ServerResult:
120120

121121
tool.inputSchema["properties"]["context"] = {
122122
"type": "string",
123-
"description": "Describe why you are calling this tool and how it fits into your overall task",
123+
"description": data.options.custom_context_description,
124124
}
125125

126126
# Add context to required array if it exists

src/mcpcat/modules/overrides/official/monkey_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ async def get_more_tools_fn(context: str) -> Any:
444444

445445
tool.parameters["properties"]["context"] = {
446446
"type": "string",
447-
"description": "Describe why you are calling this tool and how it fits into your overall task",
447+
"description": current_data.options.custom_context_description,
448448
}
449449

450450
# Add to required array

src/mcpcat/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from mcpcat_api import PublishEventRequest
99
from pydantic import BaseModel
1010

11+
from mcpcat.modules.constants import DEFAULT_CONTEXT_DESCRIPTION
12+
1113
# Type alias for identify function
1214
IdentifyFunction = Callable[[dict[str, Any], Any], Optional["UserIdentity"]]
1315
# Type alias for redaction function
@@ -119,6 +121,7 @@ class MCPCatOptions:
119121
enable_report_missing: bool = True
120122
enable_tracing: bool = True
121123
enable_tool_call_context: bool = True
124+
custom_context_description: str = DEFAULT_CONTEXT_DESCRIPTION
122125
identify: IdentifyFunction | None = None
123126
redact_sensitive_information: RedactionFunction | None = None
124127
exporters: dict[str, ExporterConfig] | None = None

0 commit comments

Comments
 (0)