-
Notifications
You must be signed in to change notification settings - Fork 571
fix(mcp): emit properties:{} in list_agents inputSchema (#1889) #1892
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
Merged
EItanya
merged 3 commits into
kagent-dev:main
from
pboers1988:fix/list-agents-input-schema-1889
May 22, 2026
+87
−1
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package mcp | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/kagent-dev/kagent/go/api/v1alpha2" | ||
| mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp" | ||
| "github.com/stretchr/testify/require" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| // TestListAgentsInputSchemaHasProperties asserts that the list_agents tool | ||
| // advertises an inputSchema containing an explicit "properties" key, even | ||
| // though it accepts no arguments. OpenAI strict mode requires this. | ||
| // Regression test for https://github.com/kagent-dev/kagent/issues/1889. | ||
| func TestListAgentsInputSchemaHasProperties(t *testing.T) { | ||
| scheme := runtime.NewScheme() | ||
| require.NoError(t, v1alpha2.AddToScheme(scheme)) | ||
| kubeClient := fake.NewClientBuilder().WithScheme(scheme).Build() | ||
|
|
||
| h, err := NewMCPHandler(kubeClient, "http://unused", nil, time.Minute) | ||
| require.NoError(t, err) | ||
|
|
||
| clientTransport, serverTransport := mcpsdk.NewInMemoryTransports() | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
|
|
||
| // Run the server in a goroutine; it returns when the transport closes. | ||
| serverDone := make(chan error, 1) | ||
| go func() { | ||
| serverDone <- h.server.Run(ctx, serverTransport) | ||
| }() | ||
| // Registered first so it runs last (LIFO): after session.Close below has | ||
| // disconnected the client, cancel the context and drain the server's | ||
| // return value so the goroutine cannot leak and unexpected errors surface. | ||
| t.Cleanup(func() { | ||
| cancel() | ||
| if err := <-serverDone; err != nil && err != context.Canceled { | ||
| t.Errorf("MCP server returned unexpected error: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| client := mcpsdk.NewClient(&mcpsdk.Implementation{Name: "test", Version: "0.0.0"}, nil) | ||
| session, err := client.Connect(ctx, clientTransport, nil) | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { session.Close() }) | ||
|
|
||
| tools, err := session.ListTools(ctx, &mcpsdk.ListToolsParams{}) | ||
| require.NoError(t, err) | ||
|
|
||
| var listAgents *mcpsdk.Tool | ||
| for i := range tools.Tools { | ||
| if tools.Tools[i].Name == "list_agents" { | ||
| listAgents = tools.Tools[i] | ||
| break | ||
| } | ||
| } | ||
| require.NotNil(t, listAgents, "list_agents tool not registered") | ||
|
|
||
| raw, err := json.Marshal(listAgents.InputSchema) | ||
| require.NoError(t, err) | ||
|
|
||
| var schema map[string]any | ||
| require.NoError(t, json.Unmarshal(raw, &schema)) | ||
|
|
||
| require.Equal(t, "object", schema["type"], "inputSchema type must be object") | ||
| props, ok := schema["properties"] | ||
| require.True(t, ok, "inputSchema must include a properties key (got %s)", string(raw)) | ||
| require.IsType(t, map[string]any{}, props, "properties must be a JSON object") | ||
| require.Empty(t, props, "list_agents takes no args, properties should be empty") | ||
| require.Equal(t, false, schema["additionalProperties"], "additionalProperties must remain false") | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.