Skip to content

Commit e152a20

Browse files
committed
feat: add helper methods for tool and resource registration
Add convenience methods to simplify MCP server feature registration: - Add AddTool[In, Out] package-level generic function for type-safe tool registration - Add Server.AddResource method for resource registration - Add Server.AddResourceTemplate method for resource template registration - All helpers automatically increment internal counters for accurate stats These methods eliminate the need for users to: - Call srv.MCP() to access the underlying MCP server - Manually increment tool/resource counters after registration All changes are additive and backwards compatible. Additional changes: - Fix branding: replace all 'MCPBase' references with 'hypermcp' in DOCKER.md - Update README.md with new API examples and documentation structure - Update EXAMPLE.md to demonstrate new simplified registration pattern - Clean up go.sum dependencies
1 parent c379fd5 commit e152a20

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

DOCKER.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Docker Deployment Guide for MCPBase Servers
1+
# Docker Deployment Guide for hypermcp Servers
22

3-
This guide covers containerizing and deploying MCP servers built with MCPBase.
3+
This guide covers containerizing and deploying MCP servers built with hypermcp.
44

55
## 📋 Table of Contents
66
- [Quick Start](#quick-start)
@@ -15,7 +15,7 @@ This guide covers containerizing and deploying MCP servers built with MCPBase.
1515

1616
### 1. Copy the Example Dockerfile
1717
```bash
18-
cp pkg/mcpbase/Dockerfile.example ./Dockerfile
18+
cp Dockerfile.example ./Dockerfile
1919
```
2020

2121
### 2. Build Your Image
@@ -357,4 +357,4 @@ docker run --rm -it --entrypoint /bin/sh my-mcp-server:latest
357357

358358
---
359359

360-
**Need help?** Check the main MCPBase documentation or open an issue!
360+
**Need help?** Check the main hypermcp documentation or open an issue!

EXAMPLE.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ type EchoOutput struct {
8989

9090
// registerTools registers all tools with the MCP server
9191
func registerTools(srv *hypermcp.Server, logger *zap.Logger) {
92-
// Register a simple echo tool
93-
mcp.AddTool(
94-
srv.MCP(),
92+
// Register a simple echo tool using the helper function
93+
hypermcp.AddTool(
94+
srv,
9595
&mcp.Tool{
9696
Name: "echo",
9797
Description: "Echo back a message",
@@ -101,11 +101,10 @@ func registerTools(srv *hypermcp.Server, logger *zap.Logger) {
101101
return nil, EchoOutput{Echo: input.Message}, nil
102102
},
103103
)
104-
srv.IncrementToolCount()
105104

106105
// Add more tools here...
107106
}
108-
\`\`\`
107+
```
109108
110109
## Build and Run
111110

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,17 @@ func registerFeatures(srv *hypermcp.Server) {
110110
// Create providers
111111
myProvider := providers.NewMyProvider(srv)
112112

113-
// Register tools
114-
srv.AddTool(
113+
// Register tools using the helper function
114+
hypermcp.AddTool(
115+
srv,
115116
&mcp.Tool{
116117
Name: "my_tool",
117118
Description: "Does something cool",
118119
},
119120
myProvider.MyTool,
120121
)
121122

122-
// Register resources
123+
// Register resources using the helper method
123124
srv.AddResource(
124125
&mcp.Resource{
125126
URI: "myresource://data",
@@ -161,13 +162,18 @@ type Config struct {
161162
- `Cache() *cache.Cache` - Get the cache instance
162163
- `Logger() *zap.Logger` - Get the logger
163164
- `MCP() *mcp.Server` - Get the underlying MCP server
164-
- `AddTool(tool, handler)` - Register a tool
165-
- `AddResource(resource, handler)` - Register a resource
166-
- `AddResourceTemplate(template, handler)` - Register a resource template
165+
- `AddResource(resource, handler)` - Register a resource (auto-increments counter)
166+
- `AddResourceTemplate(template, handler)` - Register a resource template (auto-increments counter)
167167
- `LogRegistrationStats()` - Log tool/resource counts
168168
- `Run(ctx, transport)` - Start the server
169169
- `Shutdown(ctx)` - Gracefully shutdown
170170

171+
### Package-Level Functions
172+
173+
- `AddTool[In, Out](srv, tool, handler)` - Register a tool (auto-increments counter)
174+
- `New(cfg, logger)` - Create a new server instance
175+
- `RunWithTransport(ctx, srv, transportType, logger)` - Start server with specified transport
176+
171177
### Transport
172178

173179
```go

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zI
2626
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
2727
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
2828
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
29-
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
30-
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
3129
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
3230
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
3331
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
3432
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
35-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
36-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3733
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
3834
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
3935
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=

server.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ func (s *Server) Run(ctx context.Context, transport mcp.Transport) error {
123123
return s.mcp.Run(ctx, transport)
124124
}
125125

126+
// AddTool registers a tool with the MCP server and increments the tool counter
127+
func AddTool[In, Out any](s *Server, tool *mcp.Tool, handler mcp.ToolHandlerFor[In, Out]) {
128+
mcp.AddTool(s.mcp, tool, handler)
129+
s.IncrementToolCount()
130+
}
131+
132+
// AddResource registers a resource with the MCP server and increments the resource counter
133+
func (s *Server) AddResource(resource *mcp.Resource, handler mcp.ResourceHandler) {
134+
s.mcp.AddResource(resource, handler)
135+
s.IncrementResourceCount()
136+
}
137+
138+
// AddResourceTemplate registers a resource template with the MCP server and increments the resource counter
139+
func (s *Server) AddResourceTemplate(template *mcp.ResourceTemplate, handler mcp.ResourceHandler) {
140+
s.mcp.AddResourceTemplate(template, handler)
141+
s.IncrementResourceCount()
142+
}
143+
126144
// Shutdown performs cleanup
127145
func (s *Server) Shutdown(ctx context.Context) error {
128146
s.logger.Info("shutting down server")

0 commit comments

Comments
 (0)