Skip to content

feat(mcp): Track and broadcast MCP instance changes - #745

Merged
haiphucnguyen merged 2 commits into
askimo-ai:mainfrom
larry-ca:feature/cache-mcp-info
Oct 3, 2026
Merged

haiphucnguyen merged 2 commits into
askimo-ai:mainfrom
larry-ca:feature/cache-mcp-info

Conversation

@larry-ca

@larry-ca larry-ca commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Askimo load the mcp tools in every chat conversation as new ones. This PR to modify the McpInstanceService to cache the tool results

Related Issue(s)

Type of Change

  • [] 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📝 Documentation
  • ♻️ Refactor (no functional change)
  • 🧪 Tests
  • 🔧 Chore / tooling / CI

What Changed & Why

Askimo load the mcp tools in every chat conversation as new ones. This PR to modify the McpInstanceService to cache the tool results hence it does not need to re-connect mcp servers in every chat conversation

How to Test

./gradlew test

Screenshots / Recordings (if applicable)

Checklist

  • I have read the CONTRIBUTING guide
  • My branch is up to date with main
  • I ran ./gradlew spotlessApply and ./gradlew detekt locally
  • I ran ./gradlew test and all tests pass
  • I added/updated tests for my changes (if applicable)
  • I added/updated documentation (if applicable)
  • My commits are signed off (DCO) — git commit -s
  • This PR is focused on a single feature/fix

Additional Notes

- Introduces `McpInstancesChangedEvent` to notify components of server status updates.
- The `McpInstanceService` now broadcasts this event after cache invalidation, synchronizing UI state.
- Formalizes server metadata using the new `McpServerInfo` structure.
- Updates the chat input field to react to and utilize the new event flow for instance management.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Cache lifetime and concurrency issues can make MCP tools unavailable or permanently stale.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds shared MCP tool caching and broadcasts configuration changes so chat UIs refresh without reconnecting on every session.

Changes:

  • Adds cached MCP server/tool metadata.
  • Broadcasts MCP instance changes through the event bus.
  • Updates chat tool selection to consume and refresh shared cached data.
File Description
McpServerInfo.kt Defines shared MCP server/tool metadata.
McpInstanceService.kt Adds caches, server listing, and change events.
McpInstancesChangedEvent.kt Defines the internal MCP change event.
ChatInputField.kt Uses cached server data and listens for changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Indefinite caching can permanently serve stale tools, and one server failure can suppress all healthy servers.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Isolate per-server MCP tool fetch failures

shared/​src/​main/​kotlin/​io/​askimo/​core/​mcp/​McpInstanceService.kt:401

fetchToolsFromInstance can throw directly when mcpClient.listTools() fails, so this getOrElse does not isolate failures per server. The outer runCatching then aborts the entire map, causing one unavailable MCP server to hide every healthy server from the popup. Wrap the call itself so each server failure produces only that server's empty tool list.

@haiphucnguyen haiphucnguyen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @larry-ca !

@haiphucnguyen
haiphucnguyen merged commit 6b4d668 into askimo-ai:main Oct 3, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants