Skip to content

Commit 69e2a24

Browse files
yigitkonurclaude
andcommitted
feat: add SAMPLE_TOOL_NAME env var for dynamic tool registration
- Demonstrates runtime configuration pattern common in MCP servers - When set, registers a simple echo tool with the specified name - Tool accepts a 'value' parameter and returns 'test string print: {value}' - Updated README to document the educational purpose of this feature - Minimal implementation changes to maintain code simplicity This feature shows how MCP servers can be configured at runtime through environment variables, a standard practice for server configuration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7652985 commit 69e2a24

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,15 @@ npx @modelcontextprotocol/inspector --cli http://localhost:1071/mcp
300300

301301
The server is configured using environment variables, making it perfect for containerized deployments.
302302

303-
| Variable | Description | Default |
304-
| :------------------ | :---------------------------------------------------------------- | :---------------- |
305-
| `PORT` | The port for the HTTP server to listen on. | `1071` |
306-
| `LOG_LEVEL` | Logging verbosity (`debug`, `info`, `warn`, `error`). | `info` |
307-
| `CORS_ORIGIN` | Allowed origin for CORS. **Must be restricted in production.** | `*` |
308-
| `RATE_LIMIT_MAX` | Max requests per window per IP. | `1000` |
309-
| `RATE_LIMIT_WINDOW` | Rate limit window in milliseconds. | `900000` (15 min) |
310-
| `NODE_ENV` | Sets the environment. Use `production` for Express optimizations. | `development` |
303+
| Variable | Description | Default |
304+
| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------- |
305+
| `PORT` | The port for the HTTP server to listen on. | `1071` |
306+
| `LOG_LEVEL` | Logging verbosity (`debug`, `info`, `warn`, `error`). | `info` |
307+
| `CORS_ORIGIN` | Allowed origin for CORS. **Must be restricted in production.** | `*` |
308+
| `RATE_LIMIT_MAX` | Max requests per window per IP. | `1000` |
309+
| `RATE_LIMIT_WINDOW` | Rate limit window in milliseconds. | `900000` (15 min) |
310+
| `NODE_ENV` | Sets the environment. Use `production` for Express optimizations. | `development` |
311+
| `SAMPLE_TOOL_NAME` | **(Educational)** Demonstrates dynamic tool registration via environment variables. When set, adds a simple echo tool with the specified name that takes a `value` parameter and returns `test string print: {value}`. This pattern shows how MCP servers can be configured at runtime. | None |
311312

312313
### Deployment
313314

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ function createMCPServer(): McpServer {
285285
sampleToolName, // Tool name from environment variable
286286
'Educational echo tool for learning MCP concepts', // Human-readable description
287287
schemas.sampleTool.shape, // Zod schema for parameter validation
288-
async ({ message }): Promise<CallToolResult> => ({
288+
async ({ value }): Promise<CallToolResult> => ({
289289
content: [
290290
{
291291
type: 'text',
292-
text: `Sample tool "${sampleToolName}" received: ${message}`,
292+
text: `test string print: ${value}`,
293293
},
294294
],
295295
}),

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const schemas = {
4747
* Demonstrates dynamic tool registration based on configuration.
4848
*/
4949
sampleTool: z.object({
50-
message: z.string().describe('Message to echo back'),
50+
value: z.string().describe('Value to be prefixed and returned'),
5151
}),
5252

5353
/**

0 commit comments

Comments
 (0)