Skip to content

Commit 5bfcf69

Browse files
committed
Enhance MCP server context management and documentation
- Added support for pre-configured context in MCP server commands, allowing users to specify `--pulsar-instance` and `--pulsar-cluster` flags. - Updated `RegisterContextTools` function to conditionally skip context tool registration based on provided CLI flags, improving usability. - Enhanced README.md with new command examples and notes regarding context management behavior when using specific flags. - Added comments in the code for better clarity on the context management logic.
1 parent 6ad41a2 commit 5bfcf69

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ If you want to access to your StreamNative Cloud, you will need to have followin
8989
# Start MCP server with StreamNative Cloud authentication
9090
bin/snmcp stdio --organization my-org --key-file /path/to/key-file.json
9191

92+
# Start MCP server with StreamNative Cloud authentication and pre-configured context
93+
# When --pulsar-instance and --pulsar-cluster are provided, context management tools are disabled
94+
bin/snmcp stdio --organization my-org --key-file /path/to/key-file.json --pulsar-instance my-instance --pulsar-cluster my-cluster
95+
9296
# Start MCP server with external Kafka
9397
bin/snmcp stdio --use-external-kafka --kafka-bootstrap-servers localhost:9092 --kafka-auth-type SASL_SSL --kafka-auth-mechanism PLAIN --kafka-auth-user user --kafka-auth-pass pass --kafka-use-tls --kafka-schema-registry-url https://sr.local --kafka-schema-registry-auth-user user --kafka-schema-registry-auth-pass pass
9498

@@ -106,6 +110,10 @@ docker run -i --rm -e SNMCP_ORGANIZATION=my-org -e SNMCP_KEY_FILE=/key.json -v /
106110
# Start MCP server with SSE and StreamNative Cloud authentication
107111
snmcp sse --http-addr :9090 --http-path /mcp --organization my-org --key-file /path/to/key-file.json
108112

113+
# Start MCP server with SSE and pre-configured StreamNative Cloud context
114+
# When --pulsar-instance and --pulsar-cluster are provided, context management tools are disabled
115+
snmcp sse --http-addr :9090 --http-path /mcp --organization my-org --key-file /path/to/key-file.json --pulsar-instance my-instance --pulsar-cluster my-cluster
116+
109117
# Start MCP server with SSE and external Kafka
110118
snmcp sse --http-addr :9090 --http-path /mcp --use-external-kafka --kafka-bootstrap-servers localhost:9092
111119

@@ -235,6 +243,8 @@ The StreamNative MCP Server allows you to enable or disable specific groups of f
235243
| `streamnative-cloud`| Manage StreamNative Cloud context and check resource logs | [streamnative_cloud.md](docs/tools/streamnative_cloud.md) |
236244
| `functions-as-tools` | Dynamically exposes deployed Pulsar Functions as invokable MCP tools, with automatic input/output schema handling. | [functions_as_tools.md](docs/tools/functions_as_tools.md) |
237245

246+
> **Note:** When using `--pulsar-instance` and `--pulsar-cluster` flags together, context management tools (`sncloud_context_use_cluster`) are automatically disabled since the context is pre-configured.
247+
238248
You can combine these features as needed using the `--features` flag. For example, to enable only Pulsar client features:
239249
```bash
240250
# Enable only Pulsar client features

pkg/cmd/mcp/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func newMcpServer(_ context.Context, configOpts *ServerOptions, logrusLogger *lo
5454

5555
s = mcpServer.MCPServer
5656
mcp.RegisterPrompts(s)
57-
mcp.RegisterContextTools(s, configOpts.Features)
57+
// Skip context tools if pulsar instance and cluster are provided via CLI
58+
skipContextTools := snConfig.Context.PulsarInstance != "" && snConfig.Context.PulsarCluster != ""
59+
mcp.RegisterContextTools(s, configOpts.Features, skipContextTools)
5860
mcp.StreamNativeAddLogTools(s, configOpts.ReadOnly, configOpts.Features)
5961
mcp.StreamNativeAddResourceTools(s, configOpts.ReadOnly, configOpts.Features)
6062
}

pkg/mcp/sncontext_tools.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import (
2929
"github.com/streamnative/streamnative-mcp-server/pkg/common"
3030
)
3131

32-
func RegisterContextTools(s *server.MCPServer, features []string) {
32+
func RegisterContextTools(s *server.MCPServer, features []string, skipContextTools bool) {
3333
if !slices.Contains(features, string(FeatureStreamNativeCloud)) && !slices.Contains(features, string(FeatureAll)) {
3434
return
3535
}
36+
3637
// Add whoami tool
3738
whoamiTool := mcp.NewTool("sncloud_context_whoami",
3839
mcp.WithDescription("Display the currently logged-in service account. "+
@@ -50,7 +51,10 @@ func RegisterContextTools(s *server.MCPServer, features []string) {
5051
mcp.Description("The name of the pulsar cluster to use"),
5152
),
5253
)
53-
s.AddTool(setContextTool, handleSetContext)
54+
// Skip registering context tools if context is already provided
55+
if !skipContextTools {
56+
s.AddTool(setContextTool, handleSetContext)
57+
}
5458

5559
// Add available-contexts tool
5660
availableContextsTool := mcp.NewTool("sncloud_context_available_clusters",

0 commit comments

Comments
 (0)