feat(bazaar): add MCP resource type support to Go SDK#1967
Open
avidreder wants to merge 6 commits intox402-foundation:mainfrom
Open
feat(bazaar): add MCP resource type support to Go SDK#1967avidreder wants to merge 6 commits intox402-foundation:mainfrom
avidreder wants to merge 6 commits intox402-foundation:mainfrom
Conversation
Add MCP tool discovery extensions to the bazaar package, achieving parity with the TypeScript and Python SDKs. Servers can now declare MCP tool discovery extensions alongside HTTP resources, and facilitators can detect and extract them from payment payloads. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…e tests - Fix transport schema enum to include both valid values (streamable-http, sse) instead of only the provided value, matching TypeScript SDK behavior - Fix doc.go examples to use bazaar.BAZAAR.Key() instead of bazaar.BAZAAR - Inline createMcpDiscoveryExtension into DeclareMcpDiscoveryExtension - Add negative validation tests for wrong type and empty toolName - Add edge case tests for whitespace-only toolName and invalid transport Co-Authored-By: Claude <noreply@anthropic.com>
Add Extensions field to PaymentWrapperConfig and pass it through to the PaymentRequired struct in 402 responses. This brings the MCP payment wrapper to parity with the HTTP middleware's RouteConfig.Extensions support, enabling bazaar discovery extensions in MCP tool responses. - Add Extensions map to PaymentWrapperConfig (types.go) - Set extensions in paymentRequiredResult (server.go) - Add unit tests for extensions present/absent in 402 (server_test.go) - Declare bazaar MCP extension in E2E server (main.go) - Add bazaar extension integration test (mcp_evm_test.go) Co-Authored-By: Claude <noreply@anthropic.com>
Add extensions support to the TS MCP PaymentWrapperConfig and pass it through to createPaymentRequiredResponse so bazaar discovery metadata appears in 402 responses. Wire the E2E server with declareDiscoveryExtension for the get_weather tool. Add Go mocked-transport integration tests (5 cases) covering the full client↔server payment flow to match TS mcp-payment-flow.test.ts coverage. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
| // Example: map[string]interface{}{"city": "San Francisco"}, | ||
| // }) | ||
| func DeclareMcpDiscoveryExtension(config types.DeclareMcpDiscoveryConfig) (types.DiscoveryExtension, error) { | ||
| if config.ToolName == "" { |
Contributor
There was a problem hiding this comment.
nit: strings.TrimSpace(config.ToolName) == "" to avoid whitespace strings
| expect(err.paymentRequired).toBeDefined(); | ||
| // Verify bazaar extension is present if the server was configured with it | ||
| // This test validates extension passthrough from server to client | ||
| if (err.paymentRequired?.extensions?.bazaar) { |
Contributor
There was a problem hiding this comment.
Test is called should include bazaar extensions in 402 response however this check bypasses the asserts if the extension is not present
|
|
||
| // Current implementation only checks for empty string, so whitespace passes declaration. | ||
| // This documents the current behavior. | ||
| require.NoError(t, err) |
Contributor
There was a problem hiding this comment.
This test says should return error when toolName is whitespace-only, but the actual assert is for success, because prior to this whitespace was being let through
| require.True(t, ok) | ||
| assert.Equal(t, bazaar.McpTransport("custom-protocol"), mcpInput.Transport) | ||
|
|
||
| // But schema validation should fail because transport enum only allows known values |
Contributor
There was a problem hiding this comment.
i don't think we want the schema validation to fail if transport is a value that isn't in the enum?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
McpInput,McpTransport,McpDiscoveryInfo,DeclareMcpDiscoveryConfig) to the shared types package and re-export from bazaarDeclareMcpDiscoveryExtension()for servers to declare MCP tool resources with tool name, input schema, transport, description, and exampleDiscoveryInfo.UnmarshalJSONto discriminatetype: "mcp"from HTTP inputs, enabling correct JSON round-tripsEnrichDeclaration()so MCP extensions pass through without HTTP method narrowing or dynamic route extractionDiscoveredResourcewithToolNamefield and update bothExtractDiscoveredResourceFromPaymentPayloadandExtractDiscoveredResourceFromPaymentRequiredto handle MCP extractionTest plan
TestDeclareMcpDiscoveryExtension— full config, minimal config, missing toolName/inputSchema errors, transport variantsTestValidateDiscoveryExtension_MCP— schema validation passes for MCP extensionsTestDiscoveryInfoUnmarshalJSON_MCP— JSON round-trip correctly producesMcpInputTestExtractDiscoveredResourceFromPaymentPayload_MCP— v2 MCP extension in PaymentPayload extractsToolNameTestExtractDiscoveredResourceFromPaymentRequired_MCP— v2 MCP in PaymentRequiredTestBazaarResourceServerExtension_MCP— EnrichDeclaration passes MCP through unchanged (including with dynamic route context)TestExtractDiscoveryInfoFromExtension_MCP— direct extraction from MCP extensiongo test ./...passes🤖 Generated with Claude Code