Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
183 lines
5.4 KiB
TypeScript
183 lines
5.4 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import path from 'path'
|
|
import fs from 'fs/promises'
|
|
import { getDistDir } from 'next-test-utils'
|
|
|
|
describe('mcp-server get_server_action_by_id tool', () => {
|
|
const { next } = nextTestSetup({
|
|
files: new FileRef(path.join(__dirname, 'fixtures', 'actions-app')),
|
|
})
|
|
|
|
it('should return action details via get_server_action_by_id tool', async () => {
|
|
const mcpEndpoint = `${next.url}/_next/mcp`
|
|
|
|
// Visit the page to trigger action registration
|
|
await next.render('/')
|
|
|
|
// Read the manifest to get a valid action ID
|
|
const manifestPath = path.join(
|
|
next.testDir,
|
|
getDistDir(),
|
|
'server',
|
|
'server-reference-manifest.json'
|
|
)
|
|
const manifestContent = await fs.readFile(manifestPath, 'utf-8')
|
|
const manifest = JSON.parse(manifestContent)
|
|
|
|
// Get the first action ID from the manifest
|
|
const actionId = Object.keys(manifest.node || {})[0]
|
|
expect(actionId).toBeTruthy()
|
|
|
|
// Call get_server_action_by_id tool
|
|
const callToolResponse = await fetch(mcpEndpoint, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json, text/event-stream',
|
|
},
|
|
body: JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-1',
|
|
method: 'tools/call',
|
|
params: {
|
|
name: 'get_server_action_by_id',
|
|
arguments: {
|
|
actionId,
|
|
},
|
|
},
|
|
}),
|
|
})
|
|
|
|
const callToolText = await callToolResponse.text()
|
|
const callToolDataMatch = callToolText.match(/data: ({.*})/s)
|
|
expect(callToolDataMatch).toBeTruthy()
|
|
|
|
const callToolResult = JSON.parse(callToolDataMatch![1])
|
|
expect(callToolResult).toMatchObject({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-1',
|
|
result: {
|
|
content: [{ type: 'text', text: expect.any(String) }],
|
|
},
|
|
})
|
|
|
|
const actionDetails = JSON.parse(callToolResult.result.content[0].text)
|
|
expect(actionDetails).toMatchObject({
|
|
actionId,
|
|
runtime: 'node',
|
|
filename: expect.stringContaining('app/actions.ts'),
|
|
functionName: expect.any(String),
|
|
})
|
|
})
|
|
|
|
it('should return error for non-existent action ID', async () => {
|
|
const mcpEndpoint = `${next.url}/_next/mcp`
|
|
|
|
// Call get_server_action_by_id tool with non-existent ID
|
|
const callToolResponse = await fetch(mcpEndpoint, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json, text/event-stream',
|
|
},
|
|
body: JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-2',
|
|
method: 'tools/call',
|
|
params: {
|
|
name: 'get_server_action_by_id',
|
|
arguments: {
|
|
actionId: 'non-existent-id-12345',
|
|
},
|
|
},
|
|
}),
|
|
})
|
|
|
|
const callToolText = await callToolResponse.text()
|
|
const callToolDataMatch = callToolText.match(/data: ({.*})/s)
|
|
expect(callToolDataMatch).toBeTruthy()
|
|
|
|
const callToolResult = JSON.parse(callToolDataMatch![1])
|
|
expect(callToolResult).toMatchObject({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-2',
|
|
result: {
|
|
content: [{ type: 'text', text: expect.any(String) }],
|
|
},
|
|
})
|
|
|
|
const errorResponse = JSON.parse(callToolResult.result.content[0].text)
|
|
expect(errorResponse).toMatchObject({
|
|
error: expect.stringContaining('not found'),
|
|
})
|
|
})
|
|
|
|
it('should return inline server action details', async () => {
|
|
const mcpEndpoint = `${next.url}/_next/mcp`
|
|
|
|
// Visit the page to trigger action registration
|
|
await next.render('/inline')
|
|
|
|
// Read the manifest to get inline action ID
|
|
const manifestPath = path.join(
|
|
next.testDir,
|
|
getDistDir(),
|
|
'server',
|
|
'server-reference-manifest.json'
|
|
)
|
|
const manifestContent = await fs.readFile(manifestPath, 'utf-8')
|
|
const manifest = JSON.parse(manifestContent)
|
|
|
|
// Find the inline action ID (inline actions defined in server components)
|
|
const inlineActionId = Object.keys(manifest.node || {}).find((id) => {
|
|
const action = manifest.node[id]
|
|
return (
|
|
action.filename === 'app/inline/page.tsx' &&
|
|
action.exportedName?.startsWith('$$RSC_SERVER_ACTION_')
|
|
)
|
|
})
|
|
expect(inlineActionId).toBeTruthy()
|
|
|
|
// Call get_server_action_by_id tool for inline action
|
|
const callToolResponse = await fetch(mcpEndpoint, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json, text/event-stream',
|
|
},
|
|
body: JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-3',
|
|
method: 'tools/call',
|
|
params: {
|
|
name: 'get_server_action_by_id',
|
|
arguments: {
|
|
actionId: inlineActionId,
|
|
},
|
|
},
|
|
}),
|
|
})
|
|
|
|
const callToolText = await callToolResponse.text()
|
|
const callToolDataMatch = callToolText.match(/data: ({.*})/s)
|
|
expect(callToolDataMatch).toBeTruthy()
|
|
|
|
const callToolResult = JSON.parse(callToolDataMatch![1])
|
|
expect(callToolResult).toMatchObject({
|
|
jsonrpc: '2.0',
|
|
id: 'call-tool-3',
|
|
result: {
|
|
content: [{ type: 'text', text: expect.any(String) }],
|
|
},
|
|
})
|
|
|
|
const actionDetails = JSON.parse(callToolResult.result.content[0].text)
|
|
expect(actionDetails).toMatchObject({
|
|
actionId: inlineActionId,
|
|
runtime: 'node',
|
|
filename: expect.any(String),
|
|
functionName: 'inline server action',
|
|
})
|
|
})
|
|
})
|