mcp-go Flashcards
(26 cards)
Front
Back
How do you initialize an MCP client with mcp-go
?
```go
client, err := mcp.NewClient(mcp.WithToken(“your-token”))
~~~
What’s the idiomatic way to send a request to a service using mcp-go?
```go
resp, err := client.Call(ctx, “service.name”, req)
~~~
How do you structure a custom request in mcp-go?
```go
type MyRequest struct {
Name string json:"name"
}
~~~
What Go package is typically used for handling context in mcp-go requests?
context
package from the standard library (e.g., context.Background()
).
How can you handle errors from an MCP response?
```go
if err != nil {
log.Fatalf(“error calling service: %v”, err)
}
~~~
How do you parse a JSON response from an MCP call?
```go
var resp MyResponse
err := json.Unmarshal(body, &resp)
~~~
How do you log structured information about a call in mcp-go?
Use the log
package or structured logging tools like zap
or logrus
.
What is the purpose of mcp.WithToken()
in the client setup?
It sets the authorization token used in requests to authenticate with the MCP server.
What does NewClient(ctx context.Context, opts ...Option)
return?
(*Client, error)
— Initializes a new MCP client with provided context and options.
Function signature: func WithToken(token string) Option
— what does it do?
Returns an option that sets the authentication token for the client.
How do you call a remote MCP method using a client?
client.Call(ctx, method string, req interface{}, resp interface{}) error
What is the purpose of Client.SetHeader(key, value string)
?
Sets a custom header to be sent with each request made by the client.
What does Client.SetBaseURL(url string)
do?
Overrides the default MCP server base URL used by the client.
How do you create a call context with timeout?
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
Function signature: func NewRequest(service, endpoint string, payload interface{}) *Request
— what is this for?
Constructs a new request object targeting the specified service and endpoint.
How do you decode an MCP response?
json.Unmarshal(resp.Body, &yourStruct)
— standard Go JSON decoding.
What is Client.Debug(bool)
used for?
Enables or disables debug logging for the MCP client.
Function signature: WithDescription(desc string) ToolOption
— what’s it for?
Sets a human-readable description for a tool.
What does WithString(name string, opts ...PropertyOption)
do?
Adds a string property to the tool schema with optional metadata.
Purpose of Required() PropertyOption
?
Marks a schema property as required in tool or argument definitions.
What does Enum(values ...any)
provide when defining a property?
Restricts allowed values to a predefined set.
Function signature: WithArgument(name string, opts ...ArgumentOption)
— use?
Adds a named argument to a prompt, with options like required or description.
What is WithMIMEType(mime string)
used for?
Sets the MIME type for a resource, e.g. application/json.