Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/update-mcp-scenario-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/mcp': minor
---

MCP server: Add Create, Customize, Delegate, Edit and View scenario patterns to the `list_patterns` and `get_pattern` tools.
25 changes: 25 additions & 0 deletions packages/mcp/src/primer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,31 @@ const patterns: Array<Pattern> = [
name: 'Copy',
category: 'scenario',
},
{
id: 'create',
name: 'Create',
category: 'scenario',
},
{
id: 'customize',
name: 'Customize',
category: 'scenario',
},
{
id: 'delegate',
name: 'Delegate',
category: 'scenario',
},
{
id: 'delete',
name: 'Delete',
category: 'scenario',
},
{
id: 'edit',
name: 'Edit',
category: 'scenario',
},
{
id: 'filter',
name: 'Filter',
Expand All @@ -66,6 +86,11 @@ const patterns: Array<Pattern> = [
name: 'Search',
category: 'scenario',
},
{
id: 'view',
name: 'View',
category: 'scenario',
},
{
id: 'data-visualization',
name: 'Data Visualization',
Expand Down
38 changes: 38 additions & 0 deletions packages/mcp/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@ describe('MCP server', () => {
)
})

it('lists every published scenario pattern', async () => {
const result = await client.callTool({name: 'list_patterns'})
const scenarioPatterns = ['Copy', 'Create', 'Customize', 'Delegate', 'Delete', 'Edit', 'Filter', 'Search', 'View']

expect(result.content).toContainEqual(
expect.objectContaining({
type: 'text',
text: expect.stringContaining(
`## Scenario patterns\n\n${scenarioPatterns.map(name => `- ${name}`).join('\n')}`,
),
}),
)
})

it.each([
{name: 'Create', id: 'create'},
{name: 'Customize', id: 'customize'},
{name: 'Delegate', id: 'delegate'},
{name: 'Edit', id: 'edit'},
{name: 'View', id: 'view'},
])('retrieves the $name scenario pattern from its published URL', async ({name, id}) => {
vi.mocked(fetch).mockResolvedValue(new Response(`<main><h1>${name}</h1></main>`))

const result = await client.callTool({
name: 'get_pattern',
arguments: {name},
})

expect(fetch).toHaveBeenCalledTimes(1)
expect(vi.mocked(fetch).mock.calls[0]?.[0].toString()).toBe(`https://primer.style/product/scenario-patterns/${id}`)
expect(result.content).toContainEqual(
expect.objectContaining({
type: 'text',
text: expect.stringContaining(`Here are the guidelines for the \`${name}\` pattern for Primer:`),
}),
)
})

it('requires between 2 and 10 names', async () => {
const tooFew = await callBatch(['Button'])
const tooMany = await callBatch(Array.from({length: 11}, (_, index) => `Component${index}`))
Expand Down
4 changes: 2 additions & 2 deletions packages/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ ${text}`,
'list_patterns',
{
description:
'List all of the patterns available from Primer React. Scenario patterns describe specific user tasks (copy, delete, filter, search). Prefer a scenario pattern when one fits the task, and fall back to the more generic UI patterns otherwise.',
'List all of the patterns available from Primer React. Scenario patterns describe specific user tasks. Prefer a scenario pattern when one fits the task, and fall back to the more generic UI patterns otherwise.',
annotations: {readOnlyHint: true},
},
async () => {
Expand Down Expand Up @@ -471,7 +471,7 @@ ${ui.join('\n')}`,
'get_pattern',
{
description:
'Get a specific pattern by name. Scenario patterns describe specific user tasks (copy, delete, filter, search). Prefer a scenario pattern when one fits the task, and fall back to the more generic UI patterns otherwise.',
'Get a specific pattern by name. Scenario patterns describe specific user tasks. Prefer a scenario pattern when one fits the task, and fall back to the more generic UI patterns otherwise.',
inputSchema: z.object({
name: z.string().describe('The name of the pattern to retrieve'),
}),
Expand Down
Loading