Add title to tools, resources, prompts (#972)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
029f434109
commit
a2f8766a8a
4 changed files with 481 additions and 46 deletions
|
|
@ -123,7 +123,7 @@ class Server:
|
|||
for item in tools_response:
|
||||
if isinstance(item, tuple) and item[0] == "tools":
|
||||
tools.extend(
|
||||
Tool(tool.name, tool.description, tool.inputSchema)
|
||||
Tool(tool.name, tool.description, tool.inputSchema, tool.title)
|
||||
for tool in item[1]
|
||||
)
|
||||
|
||||
|
|
@ -189,9 +189,14 @@ class Tool:
|
|||
"""Represents a tool with its properties and formatting."""
|
||||
|
||||
def __init__(
|
||||
self, name: str, description: str, input_schema: dict[str, Any]
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
input_schema: dict[str, Any],
|
||||
title: str | None = None,
|
||||
) -> None:
|
||||
self.name: str = name
|
||||
self.title: str | None = title
|
||||
self.description: str = description
|
||||
self.input_schema: dict[str, Any] = input_schema
|
||||
|
||||
|
|
@ -211,13 +216,20 @@ class Tool:
|
|||
arg_desc += " (required)"
|
||||
args_desc.append(arg_desc)
|
||||
|
||||
return f"""
|
||||
Tool: {self.name}
|
||||
Description: {self.description}
|
||||
# Build the formatted output with title as a separate field
|
||||
output = f"Tool: {self.name}\n"
|
||||
|
||||
# Add human-readable title if available
|
||||
if self.title:
|
||||
output += f"User-readable title: {self.title}\n"
|
||||
|
||||
output += f"""Description: {self.description}
|
||||
Arguments:
|
||||
{chr(10).join(args_desc)}
|
||||
"""
|
||||
|
||||
return output
|
||||
|
||||
|
||||
class LLMClient:
|
||||
"""Manages communication with the LLM provider."""
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ def main(port: int, transport: str) -> int:
|
|||
return [
|
||||
types.Prompt(
|
||||
name="simple",
|
||||
title="Simple Assistant Prompt",
|
||||
description="A simple prompt that can take optional context and topic "
|
||||
"arguments",
|
||||
arguments=[
|
||||
|
|
|
|||
|
|
@ -5,9 +5,18 @@ from mcp.server.lowlevel import Server
|
|||
from pydantic import AnyUrl, FileUrl
|
||||
|
||||
SAMPLE_RESOURCES = {
|
||||
"greeting": "Hello! This is a sample text resource.",
|
||||
"help": "This server provides a few sample text resources for testing.",
|
||||
"about": "This is the simple-resource MCP server implementation.",
|
||||
"greeting": {
|
||||
"content": "Hello! This is a sample text resource.",
|
||||
"title": "Welcome Message",
|
||||
},
|
||||
"help": {
|
||||
"content": "This server provides a few sample text resources for testing.",
|
||||
"title": "Help Documentation",
|
||||
},
|
||||
"about": {
|
||||
"content": "This is the simple-resource MCP server implementation.",
|
||||
"title": "About This Server",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -28,6 +37,7 @@ def main(port: int, transport: str) -> int:
|
|||
types.Resource(
|
||||
uri=FileUrl(f"file:///{name}.txt"),
|
||||
name=name,
|
||||
title=SAMPLE_RESOURCES[name]["title"],
|
||||
description=f"A sample text resource named {name}",
|
||||
mimeType="text/plain",
|
||||
)
|
||||
|
|
@ -43,7 +53,7 @@ def main(port: int, transport: str) -> int:
|
|||
if name not in SAMPLE_RESOURCES:
|
||||
raise ValueError(f"Unknown resource: {uri}")
|
||||
|
||||
return SAMPLE_RESOURCES[name]
|
||||
return SAMPLE_RESOURCES[name]["content"]
|
||||
|
||||
if transport == "sse":
|
||||
from mcp.server.sse import SseServerTransport
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ def main(port: int, transport: str) -> int:
|
|||
return [
|
||||
types.Tool(
|
||||
name="fetch",
|
||||
title="Website Fetcher",
|
||||
description="Fetches a website and returns its content",
|
||||
inputSchema={
|
||||
"type": "object",
|
||||
|
|
|
|||
Loading…
Reference in a new issue