MCP - Add tokens resource - #3989
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds MCP token resources to the packages/mcp server so clients can query the HDS token catalog via hds://tokens (index) and hds://tokens/{tokenKey} (detail), backed by a lazily loaded in-memory store sourced from @hashicorp/design-system-tokens.
Changes:
- Registers new token MCP resources and wraps all resource handlers with a safe error-response wrapper.
- Implements token index/detail resources with JSON-serializable shaping for unknown
$value/originaltoken payloads. - Adds token catalog store utilities (Zod schema parsing, lookup key normalization, indexing, and search helpers).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/mcp/src/resources/utils.ts | Updates resource response typing to MCP SDK ReadResourceResult and standardizes safe handler wrapping. |
| packages/mcp/src/resources/index.ts | Registers token resources and wraps readCallbacks with withSafeResourceHandler. |
| packages/mcp/src/resources/tokens.ts | Introduces hds://tokens and hds://tokens/{tokenKey} resources and JSON-safe serialization helpers. |
| packages/mcp/src/resources/stores/tokens/store.ts | Adds loader/index for the published tokens catalog JSON plus list/get/search APIs. |
| packages/mcp/src/resources/stores/tokens/schema.ts | Defines Zod schemas/types for token catalog rows and token typing. |
| packages/mcp/src/resources/stores/tokens/lookup.ts | Adds normalization, token typing, summary/record shaping, and lookup key generation. |
8bb65c1 to
1e1cec6
Compare
5d9a0f8 to
85308a6
Compare
a145bc7 to
77bbb7a
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
423db53 to
c310842
Compare
dchyun
left a comment
There was a problem hiding this comment.
Tested server locally and all queries produced expected results. Note: This schema will have to be updated once the Carbonization work is merged.
| value: string, | ||
| limit = 100, | ||
| ): string[] => { | ||
| const query = value.trim().toLowerCase(); |
There was a problem hiding this comment.
[Suggestion] Would it be useful to support a query being done with the cssVar name as well? We could have something here to strip out -- from the query.
I'm not sure how the AI interacts with the MCP server commands, but I'm curious if an AI ran into an HDS CSS variable if it would have the context to use the command with a properly formatted query or if it would try searching with the CSS variable name.
There was a problem hiding this comment.
Agreed, good call. Added -- stripping directly into normalizeTokenLookupKey alongside the existing curly brace handling, so CSS var lookup works automatically everywhere.
|
|
||
| it("decodes token keys before reading the store", async () => { | ||
| const result = await resource.readCallback( | ||
| new URL("hds://tokens/%7Bcolor.foreground.action%7D"), |
There was a problem hiding this comment.
[Suggestion] Do we want to test for other query options as well? Or is that already covered enough by the completeTokenKeys test?
Cases we could cover
{color.foreground.action}(already tested here)color.foreground.actionCOLOR.FOREGROUND.ACTIONcolor-foreground-action
There was a problem hiding this comment.
The readCallback test in this file is specifically testing URI decode behavior (the %7B...%7D → {color.foreground.action} path), so the callback test itself doesn't need to be exhaustive on query formats
Co-authored-by: Dylan Hyun <dylan.hyun@hashicorp.com>
Co-authored-by: Dylan Hyun <dylan.hyun@hashicorp.com>
📌 Summary
Adds MCP token resources on top of the shared resource infra branch by wiring in a tokens catalog index/detail API (
hds://tokensandhds://tokens/{tokenKey}).🛠️ Detailed description
packages/mcp/src/resources/index.ts.packages/mcp/src/resources/tokens.ts:get_hds_tokensfor full catalog summariesget_hds_tokenfor token lookup by key/path/namepackages/mcp/src/resources/stores/tokens/:schema.tsfor Zod parsing/typing of token catalog rowslookup.tsfor normalization, token typing, and lookup key generationstore.tsfor loading@hashicorp/design-system-tokensdocs JSON, indexing, list/get/search support.Focus review on:
hds://tokens, template variable handling, not-found/missing-key responses).withSafeResourceHandlerandtoJsonResourceResponse.$value/originalpayload shapes.🔗 External links
Jira ticket: HDS-6483
💬 Please consider using conventional comments when reviewing this PR.
📋 PCI review checklist
Examples of changes to controls include access controls, encryption, logging, etc.
Examples include changes to operating systems, ports, protocols, services, cryptography-related components, PII processing code, etc.