Skip to content

Commit d60749b

Browse files
committed
docs: Add title field support to all example applications
Update all example applications to demonstrate new title functionality: - custom_context: Add WithTitle for authenticated request tool - dynamic_path: Add WithTitle for echo tool - everything: Add comprehensive title support for all resources, prompts, and tools - in_process: Add WithTitle for dummy tool - typed_tools: Add WithTitle for greeting tool
1 parent dd458b4 commit d60749b

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

examples/custom_context/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func NewMCPServer() *MCPServer {
110110
server.WithToolCapabilities(true),
111111
)
112112
mcpServer.AddTool(mcp.NewTool("make_authenticated_request",
113+
mcp.WithTitle("Authenticated HTTP Request Tool"),
113114
mcp.WithDescription("Makes an authenticated request"),
114115
mcp.WithString("message",
115116
mcp.Description("Message to echo"),

examples/dynamic_path/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919
mcpServer := server.NewMCPServer("dynamic-path-example", "1.0.0")
2020

2121
// Add a trivial tool for demonstration
22-
mcpServer.AddTool(mcp.NewTool("echo"), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
22+
mcpServer.AddTool(mcp.NewTool("echo", mcp.WithTitle("Echo Message Tool")), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
2323
return mcp.NewToolResultText(fmt.Sprintf("Echo: %v", req.GetArguments()["message"])), nil
2424
})
2525

examples/everything/main.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ func NewMCPServer() *server.MCPServer {
7474
mcpServer.AddResource(mcp.NewResource("test://static/resource",
7575
"Static Resource",
7676
mcp.WithMIMEType("text/plain"),
77+
mcp.WithResourceTitle("Static Text Resource"),
7778
), handleReadResource)
7879
mcpServer.AddResourceTemplate(
7980
mcp.NewResourceTemplate(
8081
"test://dynamic/resource/{id}",
8182
"Dynamic Resource",
83+
mcp.WithTemplateTitle("Dynamic Resource Template"),
8284
),
8385
handleResourceTemplate,
8486
)
@@ -90,9 +92,11 @@ func NewMCPServer() *server.MCPServer {
9092

9193
mcpServer.AddPrompt(mcp.NewPrompt(string(SIMPLE),
9294
mcp.WithPromptDescription("A simple prompt"),
95+
mcp.WithPromptTitle("Simple Prompt Example"),
9396
), handleSimplePrompt)
9497
mcpServer.AddPrompt(mcp.NewPrompt(string(COMPLEX),
9598
mcp.WithPromptDescription("A complex prompt"),
99+
mcp.WithPromptTitle("Complex Prompt with Arguments"),
96100
mcp.WithArgument("temperature",
97101
mcp.ArgumentDescription("The temperature parameter for generation"),
98102
mcp.RequiredArgument(),
@@ -104,19 +108,23 @@ func NewMCPServer() *server.MCPServer {
104108
), handleComplexPrompt)
105109
mcpServer.AddTool(mcp.NewTool(string(ECHO),
106110
mcp.WithDescription("Echoes back the input"),
111+
mcp.WithTitle("Echo Tool"),
107112
mcp.WithString("message",
108113
mcp.Description("Message to echo"),
109114
mcp.Required(),
110115
),
111116
), handleEchoTool)
112117

113118
mcpServer.AddTool(
114-
mcp.NewTool("notify"),
119+
mcp.NewTool("notify",
120+
mcp.WithTitle("Send Notification"),
121+
),
115122
handleSendNotification,
116123
)
117124

118125
mcpServer.AddTool(mcp.NewTool(string(ADD),
119126
mcp.WithDescription("Adds two numbers"),
127+
mcp.WithTitle("Number Addition Tool"),
120128
mcp.WithNumber("a",
121129
mcp.Description("First number"),
122130
mcp.Required(),
@@ -131,6 +139,7 @@ func NewMCPServer() *server.MCPServer {
131139
mcp.WithDescription(
132140
"Demonstrates a long running operation with progress updates",
133141
),
142+
mcp.WithTitle("Long Running Operation Demo"),
134143
mcp.WithNumber("duration",
135144
mcp.Description("Duration of the operation in seconds"),
136145
mcp.DefaultNumber(10),
@@ -161,6 +170,7 @@ func NewMCPServer() *server.MCPServer {
161170
// }, s.handleSampleLLMTool)
162171
mcpServer.AddTool(mcp.NewTool(string(GET_TINY_IMAGE),
163172
mcp.WithDescription("Returns the MCP_TINY_IMAGE"),
173+
mcp.WithTitle("Tiny Image Provider"),
164174
), handleGetTinyImageTool)
165175

166176
mcpServer.AddNotificationHandler("notification", handleNotification)
@@ -172,18 +182,23 @@ func generateResources() []mcp.Resource {
172182
resources := make([]mcp.Resource, 100)
173183
for i := 0; i < 100; i++ {
174184
uri := fmt.Sprintf("test://static/resource/%d", i+1)
185+
resourceName := fmt.Sprintf("Resource %d", i+1)
186+
resourceTitle := fmt.Sprintf("Generated Resource #%d", i+1)
187+
175188
if i%2 == 0 {
176-
resources[i] = mcp.Resource{
177-
URI: uri,
178-
Name: fmt.Sprintf("Resource %d", i+1),
179-
MIMEType: "text/plain",
180-
}
189+
resources[i] = mcp.NewResource(
190+
uri,
191+
resourceName,
192+
mcp.WithMIMEType("text/plain"),
193+
mcp.WithResourceTitle(resourceTitle),
194+
)
181195
} else {
182-
resources[i] = mcp.Resource{
183-
URI: uri,
184-
Name: fmt.Sprintf("Resource %d", i+1),
185-
MIMEType: "application/octet-stream",
186-
}
196+
resources[i] = mcp.NewResource(
197+
uri,
198+
resourceName,
199+
mcp.WithMIMEType("application/octet-stream"),
200+
mcp.WithResourceTitle(resourceTitle),
201+
)
187202
}
188203
}
189204
return resources

examples/in_process/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func NewMCPServer() *server.MCPServer {
2828
server.WithToolCapabilities(true),
2929
)
3030
mcpServer.AddTool(mcp.NewTool("dummy_tool",
31+
mcp.WithTitle("Simple Demo Tool"),
3132
mcp.WithDescription("A dummy tool that returns foo bar"),
3233
), handleDummyTool)
3334

examples/typed_tools/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func main() {
3030

3131
// Add tool with complex schema
3232
tool := mcp.NewTool("greeting",
33+
mcp.WithTitle("Personalized Greeting Generator"),
3334
mcp.WithDescription("Generate a personalized greeting"),
3435
mcp.WithString("name",
3536
mcp.Required(),

0 commit comments

Comments
 (0)