stdio-server

command
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

Stdio MCP Server Example

This example demonstrates a simple MCP server that communicates over standard input/output. It provides two basic tools: an echo tool and a weather forecast tool.

Features

  • Communicates using the JSON-RPC protocol over standard I/O
  • Provides an echo tool that reflects messages back to the client
  • Provides a weather tool that generates random weather forecasts

Running the Example

go run examples/stdio-server/main.go

Usage

Once the server is running, you can send JSON-RPC requests via standard input. Here are some example requests:

Echo Tool
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"echo","parameters":{"message":"Hello, World!"}}}

This will echo back the message "Hello, World!" with a timestamp.

Weather Tool
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"weather","parameters":{"location":"New York"}}}

This will return a random weather forecast for New York.

Code Structure

  • main.go: Sets up the server and registers the tools
  • Tool handlers:
    • handleEcho: Processes echo tool requests
    • handleWeather: Processes weather tool requests

Implementation Details

The server is implemented using the Cortex MCP server platform. It uses the server.NewMCPServer function to create a server instance and registers tools using the AddTool method. Tool handlers are implemented as functions that take a context and a ToolCallRequest and return a response.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL