internal/mcp: add README.md and CONTRIBUTING.md

Move examples from package doc to README.md with package decl and
imports to ensure it's compilable.

Move status of the package from package doc to README.md.

Add core concepts of MCP with example code snippets and testing
recommendations.

Change-Id: I5bf5000b922fa3942aba922713b12d0347295811
Reviewed-on: https://go-review.googlesource.com/c/tools/+/670316
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Hongxiang Jiang 2025-05-05 16:33:23 -04:00
commit bc84c08031

View file

@ -3,8 +3,7 @@
// license that can be found in the LICENSE file.
// The mcp package provides an SDK for writing model context protocol clients
// and servers. It is a work-in-progress. As of writing, it is a prototype to
// explore the design space of client/server transport and binding.
// and servers.
//
// To get started, create either a [Client] or [Server], and connect it to a
// peer using a [Transport]. The diagram below illustrates how this works:
@ -35,31 +34,6 @@
// may define their own custom Transports by implementing the [Transport]
// interface.
//
// Here's an example that creates a client that talks to an MCP server running
// as a sidecar process:
//
// import "github.com/modelcontextprotocol/go-sdk/mcp"
// ...
// // Create a new client, with no features.
// client := mcp.NewClient("mcp-client", "v1.0.0", nil)
// // Connect to a server over stdin/stdout
// transport := mcp.NewCommandTransport(exec.Command("myserver"))
// if err := client.Connect(ctx, transport, nil); err != nil {
// log.Fatal(err)
// }
// // Call a tool on the server.
// content, err := client.CallTool(ctx, "greet", map[string]any{"name": "you"})
//
// Here is an example of the corresponding server, connected over stdin/stdout:
//
// import "github.com/modelcontextprotocol/go-sdk/mcp"
// ...
// // Create a server with a single tool.
// server := mcp.NewServer("greeter", "v1.0.0", nil)
// server.AddTool(mcp.MakeTool("greet", "say hi", SayHi))
// // Run the server over stdin/stdout, until the client diconnects
// _ = server.Run(ctx, mcp.NewStdIOTransport(), nil)
//
// # TODO
//
// - Support all content types.