{"id":28417219,"url":"https://github.com/warashi/go-modelcontextprotocol","last_synced_at":"2025-08-25T17:08:29.921Z","repository":{"id":283385481,"uuid":"949250298","full_name":"Warashi/go-modelcontextprotocol","owner":"Warashi","description":"Model Context Protocol (MCP) implementation in Go without 3rd-party dependencies","archived":false,"fork":false,"pushed_at":"2025-08-17T02:40:59.000Z","size":236,"stargazers_count":3,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-17T04:19:09.677Z","etag":null,"topics":["go","golang","mcp","modelcontextprotocol"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Warashi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-16T02:30:52.000Z","updated_at":"2025-08-17T02:40:11.000Z","dependencies_parsed_at":"2025-03-20T01:22:14.927Z","dependency_job_id":"93ccc53b-dd32-4fed-ad4e-1caa4a339999","html_url":"https://github.com/Warashi/go-modelcontextprotocol","commit_stats":null,"previous_names":["warashi/go-modelcontextprotocol"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Warashi/go-modelcontextprotocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Warashi%2Fgo-modelcontextprotocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Warashi%2Fgo-modelcontextprotocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Warashi%2Fgo-modelcontextprotocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Warashi%2Fgo-modelcontextprotocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Warashi","download_url":"https://codeload.github.com/Warashi/go-modelcontextprotocol/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Warashi%2Fgo-modelcontextprotocol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272100683,"owners_count":24873442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","mcp","modelcontextprotocol"],"created_at":"2025-06-04T04:09:57.347Z","updated_at":"2025-08-25T17:08:29.892Z","avatar_url":"https://github.com/Warashi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-modelcontextprotocol\n\n[![Test](https://github.com/Warashi/go-modelcontextprotocol/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/Warashi/go-modelcontextprotocol/actions/workflows/test.yaml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/Warashi/go-modelcontextprotocol?cache)](https://goreportcard.com/report/github.com/Warashi/go-modelcontextprotocol)\n[![GoDoc](https://pkg.go.dev/badge/github.com/Warashi/go-modelcontextprotocol.svg)](https://pkg.go.dev/github.com/Warashi/go-modelcontextprotocol)\n\n\n`go-modelcontextprotocol` is a Go library that implements the Model Context Protocol (MCP). It provides a framework for building AI/LLM service backends with support for tools, resources, and various transport mechanisms.\n\n## Project Structure\n\n- **mcp**: Core implementation of the Model Context Protocol with support for tools, resources, and server capabilities.\n- **jsonrpc2**: JSON-RPC 2.0 protocol implementation for client-server communication.\n- **jsonschema**: JSON schema validation tools for validating inputs and outputs.\n- **transport**: Transport layer implementations including stdio, SSE (Server-Sent Events), and pipe-based communication.\n- **router**: Flexible URI routing system with support for dynamic parameters and pattern matching.\n\n## Usage\n\n### Creating a Server\n\nTo create a new server, use the `NewServer` function:\n\n```go\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/Warashi/go-modelcontextprotocol/mcp\"\n)\n\nfunc main() {\n\t// Create a new server with name and version\n\tserver, err := mcp.NewServer(\"example\", \"1.0.0\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create server: %v\", err)\n\t}\n\t\n\t// Start the server using stdio transport\n\tctx := context.Background()\n\tif err := server.ServeStdio(ctx); err != nil {\n\t\tlog.Fatalf(\"Server failed: %v\", err)\n\t}\n}\n```\n\n### Adding Tools\n\nYou can add tools to the server using the provided options:\n\n```go\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/Warashi/go-modelcontextprotocol/mcp\"\n\t\"github.com/Warashi/go-modelcontextprotocol/jsonschema\"\n)\n\nfunc main() {\n\t// Create a tool with a name, description, input schema, and handler function\n\ttool := mcp.NewToolFunc(\n\t\t\"exampleTool\", \n\t\t\"An example tool\", \n\t\tjsonschema.Object{}, \n\t\tfunc(ctx context.Context, input map[string]any) (map[string]any, error) {\n\t\t\treturn map[string]any{\"result\": \"success\"}, nil\n\t\t},\n\t)\n\n\t// Create a server with the tool\n\tserver, err := mcp.NewServer(\"example\", \"1.0.0\", mcp.WithTool(tool))\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create server: %v\", err)\n\t}\n\t\n\t// Serve the server over stdin/stdout\n\tctx := context.Background()\n\tif err := server.ServeStdio(ctx); err != nil {\n\t\tlog.Fatalf(\"Server failed: %v\", err)\n\t}\n}\n```\n\n### Adding Resources\n\nYou can add static resources and resource templates:\n\n```go\nimport (\n\t\"github.com/Warashi/go-modelcontextprotocol/mcp\"\n)\n\n// Add a static resource\nresource := mcp.Resource{\n\tURI:         \"example://resource/doc\",\n\tName:        \"Example Resource\",\n\tDescription: \"An example resource\",\n\tMimeType:    \"text/plain\",\n}\n\n// Add a resource template\ntemplate := mcp.ResourceTemplate{\n\tURITemplate: \"example://resource/{id}\",\n\tName:        \"Example Template\",\n\tDescription: \"A template for accessing resources by ID\",\n\tMimeType:    \"text/plain\",\n}\n\n// Create a resource reader to serve the resources\nreader := mcp.NewResourceReaderMux()\n\n// Create the server with resources\nserver, err := mcp.NewServer(\"example\", \"1.0.0\",\n\tmcp.WithResource(resource),\n\tmcp.WithResourceTemplate(template),\n\tmcp.WithResourceReader(reader),\n)\n```\n\n### Using HTTP/SSE Transport\n\nFor web applications, you can use the SSE transport:\n\n```go\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/Warashi/go-modelcontextprotocol/mcp\"\n)\n\nfunc main() {\n\tserver, err := mcp.NewServer(\"example\", \"1.0.0\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create server: %v\", err)\n\t}\n\t\n\t// Create an SSE handler with a base URL\n\thandler, err := server.SSEHandler(\"http://localhost:8080/sse\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create SSE handler: %v\", err)\n\t}\n\t\n\t// Register the handler with your HTTP server\n\t// We need trailing slash to handle all under `/sse/` with SSE handler\n\thttp.Handle(\"/sse/\", handler)\n\tlog.Fatal(http.ListenAndServe(\":8080\", nil))\n}\n```\n\n### Running Tests\n\nTo run the tests, use the `go test` command:\n\n```sh\ngo test ./...\n```\n\n## Server Implementations Using This Library\n\n- [mcp-server-pipecd](https://github.com/Warashi/mcp-server-pipecd)\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarashi%2Fgo-modelcontextprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarashi%2Fgo-modelcontextprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarashi%2Fgo-modelcontextprotocol/lists"}