Skip to content

Add MCP conversation and memory context plumbing - #103

Merged
kentcdodds merged 6 commits into
mainfrom
cursor/memory-support-integration-in-kody-bc1a
Mar 30, 2026
Merged

kentcdodds merged 6 commits into
mainfrom
cursor/memory-support-integration-in-kody-bc1a

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Mar 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add shared MCP tool-call context helpers for short generated conversationId values and structured optional memoryContext
  • extend search, execute, and open_generated_ui to accept those fields and always return structuredContent.conversationId
  • document the new MCP contract and add focused unit and MCP E2E coverage

Testing

  • npm run test -- packages/worker/src/mcp/tools/execute.node.test.ts
  • npm run test:mcp -- packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts
Open in Web Open in Cursor 

Summary by CodeRabbit

Release Notes

  • New Features

    • MCP tools (search, execute, open_generated_ui) now accept optional conversationId and memoryContext parameters
    • System auto-generates and returns a conversation ID if not provided by the client
    • Updated documentation for tool usage and parameter guidance
  • Tests

    • Added end-to-end tests validating conversation ID generation and memory context handling across tools

cursoragent and others added 2 commits March 30, 2026 13:01
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request adds optional conversationId and memoryContext fields to MCP tools (search, execute, open_generated_ui). A new utility module provides Zod schemas and resolution logic for these fields, automatically generating a conversationId if omitted and returning it in structured response content. Updates to tool descriptions document the new optional parameters and expected behavior.

Changes

Cohort / File(s) Summary
Tool context utilities
packages/worker/src/mcp/tools/tool-call-context.ts
New module exporting Zod schemas (conversationIdInputField, memoryContextInputField) and resolveConversationId() function that generates a random alphanumeric ID if the provided value is empty, or returns the trimmed input otherwise.
MCP tool implementations
packages/worker/src/mcp/tools/search.ts, packages/worker/src/mcp/tools/execute.ts, packages/worker/src/mcp/tools/open-generated-ui.ts
Updated tool input schemas to accept optional conversationId and memoryContext fields. Modified handlers to resolve conversationId via the new utility and include the resolved value in structuredContent responses.
MCP server documentation
packages/worker/src/mcp/index.ts
Updated MCP server instruction text to document that conversationId and memoryContext are optional client-provided fields, with notes on auto-generation behavior and future memory-aware functionality.
E2E and unit tests
packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts, packages/worker/src/mcp/tools/execute.node.test.ts
Added two new E2E tests for search and execute tools validating conversationId and memoryContext handling. Updated existing open_generated_ui test and tool description test with new field assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Conversations now remember their place,
With IDs that hop through the tool-call space,
When none are provided, we craft something new—
A random identifier, fresh as morning dew!
Memory awaits, though not yet in use,
But the fields are all ready—no time to refuse! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changeset: adding conversation ID and memory context support across MCP tools with shared utilities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/memory-support-integration-in-kody-bc1a

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kentcdodds kentcdodds left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@cursoragent Let's keep casing consistent by changing it to memoryContext

@cursor

cursor Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Renamed the new MCP tool input from memory_context to memoryContext everywhere in the public contract, including tool schemas, descriptions, top-level MCP instructions, and tests, while keeping conversationId behavior unchanged.execute.ts:32-37 execute.ts:127-143 search.ts:68-72 search.ts:190-205 open-generated-ui.ts:31-32 open-generated-ui.ts:79-80 index.ts:35-36 index.ts:52-53
  • Updated the focused unit and MCP E2E coverage to assert the new memoryContext casing so the PR matches the requested API naming consistently.execute.node.test.ts:25-30 mcp-server.mcp-e2e.test.ts:43-72 mcp-server.mcp-e2e.test.ts:233-261 mcp-server.mcp-e2e.test.ts:417-452

Testing

  • ✅ npm run test -- packages/worker/src/mcp/tools/execute.node.test.ts — reran the targeted unit check because the review request only changed the public description/schema wording for the MCP tool contract. terminal:1-32
  • ✅ npm run test:mcp -- packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts — reran the MCP E2E file because it exercises the real search, execute, and open_generated_ui APIs and confirms the renamed memoryContext field is accepted end-to-end. terminal:1-31
  • I did not perform manual UI testing because this review-driven change only renamed an MCP API field; there was no visual behavior change to demonstrate, and the MCP E2E suite already covers open_generated_ui at the protocol level.


Open in Web Open in Cursor 

cursoragent and others added 3 commits March 30, 2026 13:35
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
@kentcdodds
kentcdodds marked this pull request as ready for review March 30, 2026 13:42
@github-actions

github-actions Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-103.kentcdodds.workers.dev

Worker: kody-pr-103
D1: kody-pr-103-db
KV: kody-pr-103-oauth-kv

Mocks:

Co-authored-by: me <me@kentcdodds.com>

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts (1)

258-260: Strengthen generated conversationId assertion.

Line 258–260 currently verifies only “non-empty string”. Consider asserting expected format/length so generator regressions are caught earlier.

Suggested test hardening
 expect(typeof structuredResult?.conversationId).toBe('string')
-expect((structuredResult?.conversationId ?? '').length).toBeGreaterThan(0)
+expect(structuredResult?.conversationId).toMatch(
+	/^[0-9abcdefghjkmnpqrstvwxyz]{12}$/,
+)
 expect(structuredResult?.result?.ok).toBe(true)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts` around lines 258 - 260,
The test currently only checks that structuredResult?.conversationId is a
non-empty string; update the assertions in the test (the expectations around
structuredResult and conversationId) to validate a stricter format—e.g., assert
it matches the expected pattern/length such as a UUID v4 regex or a fixed-length
alphanumeric pattern and/or a minimum length (instead of only .length > 0), so
change the checks around structuredResult?.conversationId to use a regex match
and/or explicit length equality in addition to the existing type check while
leaving the structuredResult?.result?.ok assertion intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts`:
- Around line 258-260: The test currently only checks that
structuredResult?.conversationId is a non-empty string; update the assertions in
the test (the expectations around structuredResult and conversationId) to
validate a stricter format—e.g., assert it matches the expected pattern/length
such as a UUID v4 regex or a fixed-length alphanumeric pattern and/or a minimum
length (instead of only .length > 0), so change the checks around
structuredResult?.conversationId to use a regex match and/or explicit length
equality in addition to the existing type check while leaving the
structuredResult?.result?.ok assertion intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25faa22f-30e6-4aaa-8a40-bedc889f886f

📥 Commits

Reviewing files that changed from the base of the PR and between 9979081 and 8768b8c.

📒 Files selected for processing (7)
  • packages/worker/src/mcp/index.ts
  • packages/worker/src/mcp/mcp-server.mcp-e2e.test.ts
  • packages/worker/src/mcp/tools/execute.node.test.ts
  • packages/worker/src/mcp/tools/execute.ts
  • packages/worker/src/mcp/tools/open-generated-ui.ts
  • packages/worker/src/mcp/tools/search.ts
  • packages/worker/src/mcp/tools/tool-call-context.ts

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.

2 participants