-
Notifications
You must be signed in to change notification settings - Fork 638
Add an example of an in process client #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an example of an in process client #371
Conversation
WalkthroughA new example Go program is added to demonstrate an in-process Mark3 Communication Protocol (MCP) server and client interaction. The example sets up a dummy tool on the server, initializes an in-process client, lists available tools, invokes the dummy tool, and prints the results, with error handling throughout. Changes
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @edwardcqian thanks for this! Could we please just rename it to in_process
instead of in_memory
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
examples/in_process/main.go (3)
37-40
: UnusedserverInfo
field – remove or use it
serverInfo
is stored in the struct but never referenced elsewhere in the example. Dead fields increase cognitive load and hint at missing logic.
44-49
: Shadowing the importedclient
package hurts readabilityThe variable
client, err := client.NewInProcessClient(srv) ``` hides the imported package name within the function scope and again later in `main()`. Rename the variable to avoid shadowing: ```diff - client, err := client.NewInProcessClient(srv) + cli, err := client.NewInProcessClient(srv)and adjust subsequent references (
cli.Start
,cli.Initialize
, …).
78-100
: Gracefully shut down the client/server to free resourcesThe example exits without closing the in-process client (and implicitly the embedded server). Add a
defer
as soon as the client is created:-client, err := NewMCPClient(ctx) +cli, err := NewMCPClient(ctx) if err != nil { log.Fatalf("Failed to create MCP client: %v", err) } +defer cli.client.Stop(context.Background()) // or Close(), whichever the SDK providesThis demonstrates best practice for examples.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
examples/in_process/main.go
(1 hunks)
🔇 Additional comments (1)
examples/in_process/main.go (1)
51-56
: Verify that deferringcancel()
immediately afterStart
doesn’t kill background work
Start
is invoked with a 5 s timeout, thencancel()
is deferred, meaning it executes right afterNewMCPClient
returns.
If the underlying client spawns goroutines that keep the passed context for ongoing work, they will be cancelled prematurely.Please confirm that
Start
only needs the context during its call, or propagate a longer-lived context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @edwardcqian
Description
The in memory client was quite helpful for our use case, adding an example using the in memory client.
Fixes #<issue_number> (if applicable)
Type of Change
Checklist
MCP Spec Compliance
Additional Information
Summary by CodeRabbit