commit
This commit is contained in:
70
mcp.go.bak
Normal file
70
mcp.go.bak
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
"github.com/mark3labs/mcp-go/server"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mode := os.Args[1]
|
||||
switch mode {
|
||||
case "server":
|
||||
startServer()
|
||||
case "client":
|
||||
startClient()
|
||||
}
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
// Create a new MCP server
|
||||
s := server.NewMCPServer(
|
||||
"Demo 🚀",
|
||||
"1.0.0",
|
||||
server.WithToolCapabilities(false),
|
||||
)
|
||||
|
||||
// Add tool
|
||||
tool := mcp.NewTool("hello_world",
|
||||
mcp.WithDescription("Say hello to someone"),
|
||||
mcp.WithString("name",
|
||||
mcp.Required(),
|
||||
mcp.Description("Name of the person to greet"),
|
||||
),
|
||||
)
|
||||
|
||||
// Add tool handler
|
||||
s.AddTool(tool, helloHandler)
|
||||
|
||||
// Start the stdio server
|
||||
testServer := server.NewTestServer(s,
|
||||
server.WithDynamicBasePath(func(r *http.Request, sessionID string) string {
|
||||
tenant := r.Header.Get("X-Tenant-ID")
|
||||
return "/api/" + tenant
|
||||
}),
|
||||
server.WithBaseURL("http://localhost:9090"),
|
||||
server.WithUseFullURLForMessageEndpoint(true))
|
||||
|
||||
mux := http.NewServeMux()
|
||||
// mux.Handle("/api/{tenant}/sse", testServer.)
|
||||
if err := http.ListenAndServe(":9090", mux); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
name, err := request.RequireString("name")
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil
|
||||
}
|
||||
|
||||
func startClient() {
|
||||
// Client implementation goes here
|
||||
}
|
||||
Reference in New Issue
Block a user