Skip to content

fix: three bug fixes for MCP tools and background embedding generation#219

Open
syn-zhu wants to merge 1 commit intoagentregistry-dev:mainfrom
syn-zhu:fix/misc-bug-fixes
Open

fix: three bug fixes for MCP tools and background embedding generation#219
syn-zhu wants to merge 1 commit intoagentregistry-dev:mainfrom
syn-zhu:fix/misc-bug-fixes

Conversation

@syn-zhu
Copy link
Contributor

@syn-zhu syn-zhu commented Feb 25, 2026

/kind fix

Description

Three bug fixes found while integrating AgentRegistry into a production Kubernetes platform.

  1. auth.WithSystemContext for background embedding goroutines — bare context.Background() lacks the system auth session, causing embedding updates to fail silently. Matches the pattern already used in embeddings_sse.go and embeddings.go.

  2. Nil Config map initializationget_deployment and list_deployments MCP tools return null for Config when the map is nil, breaking downstream JSON consumers. Also adds case-insensitive resource_type filtering.

  3. Default port 3000 for stdio transport — the kagent translator leaves Deployment.Port at 0 for stdio servers, which is invalid. Defaults to 3000 to match the KMCP CLI.

Fixes #217

Changes

File Change
internal/registry/service/registry_service.go context.Background()auth.WithSystemContext(context.Background()) in 2 goroutines
internal/mcp/registryserver/server.go Init nil Config maps, strings.EqualFold for resource type filter
internal/runtime/translation/kagent/kagent_translator.go Default port 3000 for stdio transport

Test plan

  • Publish a server with EMBEDDINGS_ENABLED=true → verify embedding column is populated (not NULL)
  • Call get_deployment for a deployment with no config → verify Config is {} not null
  • Call list_deployments with resource_type=server (lowercase) → verify results returned
  • Deploy a stdio MCP server via kagent translator → verify port is 3000
Fix background embedding generation silently failing due to missing auth context, nil Config map in deployment MCP tool responses, and missing default port for stdio transport in kagent translator.

…eneration

1. Use auth.WithSystemContext for background embedding goroutines

   When generating embeddings asynchronously after server/agent creation,
   the goroutine creates a bare context.Background() with no auth session.
   Downstream database operations check IsSystemSession() and fail silently.
   Fix: wrap with auth.WithSystemContext() to match the pattern used in
   embeddings_sse.go, embeddings.go, and registry_app.go.

2. Initialize nil Config map in deployment responses

   When a deployment has no config, the Config field is nil. JSON-serializing
   a nil map produces `null` instead of `{}`, which breaks MCP tool consumers
   that expect an object. Also applies case-insensitive comparison for
   resource type filtering in list_deployments.

3. Default port 3000 for stdio transport in kagent translator

   When translating a stdio-based MCP server to a kagent deployment, the
   port is left at 0 if not explicitly set. This is invalid for the transport
   adapter. Default to 3000 to match the KMCP CLI default.
@syn-zhu
Copy link
Contributor Author

syn-zhu commented Mar 5, 2026

Hi, @ilackarms gentle bump on this :)

Should be a super quick review!

outIdx := 0
for _, d := range deployments {
if args.ResourceType != "" && d.ResourceType != args.ResourceType {
if args.ResourceType != "" && !strings.EqualFold(d.ResourceType, args.ResourceType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i'm personally a bit iffy on this. it makes sense, but as far as I could tell this is the only place in the code we'd support case-insensitive

Comment on lines +376 to +380
dep := *d
if dep.Config == nil {
dep.Config = map[string]string{}
}
resp.Deployments[outIdx] = dep
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid a nil Config, would it be better to update the list method so it gets instantiated there and we wouldn't need to do this check here?

so in registry_service.go, when listing k8s deployments listKubernetesDeployments, we'd simply

config := labels
if config == nil {
  config = make(map[string]string)
}
d := {
...
  config: config
...
}

for what it's worth, our db listing code already does something similar to this, so we'd essentially be matching its behavior in the k8s listing

		if d.Config == nil {
			d.Config = make(map[string]string)
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Three issues in MCP tool handlers and background embedding generation

2 participants