-
-
Notifications
You must be signed in to change notification settings - Fork 752
Draft: Basic MCP implementation #4982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DavertMik
wants to merge
1
commit into
3.x
Choose a base branch
from
feat/mcp
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const { McpServer, ResourceTemplate } = require('@modelcontextprotocol/sdk/server/mcp.js') | ||
| const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js') | ||
| const path = require('path') | ||
| const fs = require('fs') | ||
|
|
||
| // Import core CodeceptJS modules | ||
| const Codecept = require('../lib/codecept') | ||
| const container = require('../lib/container') | ||
| const { getParamsToString } = require('../lib/parser') | ||
| const { methodsOfObject } = require('../lib/utils') | ||
| const output = require('../lib/output') | ||
| const { getConfig, getTestRoot } = require('../lib/command/utils') | ||
|
|
||
| // Simple path handling - use argument if provided, otherwise use current directory | ||
|
|
||
| const lastArg = process.argv[process.argv.length - 1] | ||
|
|
||
| const customPath = lastArg.includes('mcp.js') ? process.cwd() : lastArg | ||
|
|
||
| /** | ||
| * Start MCP Server | ||
| */ | ||
| async function startServer() { | ||
| // Disable default output | ||
| output.print = () => {} | ||
|
|
||
| // Initialize CodeceptJS | ||
| const testsPath = getTestRoot(customPath) | ||
| const config = getConfig(customPath) | ||
| const codecept = new Codecept(config, {}) | ||
|
|
||
| codecept.init(testsPath) | ||
| codecept.loadTests() | ||
|
|
||
| // Setup MCP server | ||
| const server = new McpServer({ | ||
| name: 'CodeceptJS', | ||
| version: '1.0.0', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we get the current version of codeceptjs? |
||
| url: 'https://codecept.io', | ||
| description: 'CodeceptJS Model Context Protocol Server', | ||
| }) | ||
|
|
||
| // Convert Resource: tests | ||
| server.tool('list-tests', {}, async () => { | ||
| // Use the same approach as dryRun.js to collect test information | ||
| const mocha = container.mocha() | ||
| mocha.files = codecept.testFiles | ||
| mocha.loadFiles() | ||
|
|
||
| const tests = [] | ||
|
|
||
| // Iterate through all suites and tests | ||
| for (const suite of mocha.suite.suites) { | ||
| for (const test of suite.tests) { | ||
| tests.push({ | ||
| title: test.title, | ||
| fullTitle: test.fullTitle(), | ||
| body: test.body ? test.body.toString() : '', | ||
| file: suite.file, | ||
| suiteName: suite.title, | ||
| meta: test.meta, | ||
| tags: test.tags, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Format each test as a readable text block | ||
| const formattedText = tests | ||
| .map(test => { | ||
| return [`Test: ${test.fullTitle}`, `File: ${test.file}`, `Suite: ${test.suiteName}`, test.tags && test.tags.length ? `Tags: ${test.tags?.join(', ')}` : '', '', 'Body:', test.body, '---'] | ||
| .filter(Boolean) | ||
| .join('\n') | ||
| }) | ||
| .join('\n\n') | ||
|
|
||
| return { | ||
| content: [{ type: 'text', text: formattedText }], | ||
| } | ||
| }) | ||
|
|
||
| // Convert Resource: suites | ||
| server.tool('list-suites', {}, async () => { | ||
| // Use the same approach as dryRun.js to collect suite information | ||
| const mocha = container.mocha() | ||
| mocha.files = codecept.testFiles | ||
| mocha.loadFiles() | ||
|
|
||
| const suites = [] | ||
|
|
||
| // Iterate through all suites | ||
| for (const suite of mocha.suite.suites) { | ||
| suites.push({ | ||
| title: suite.title, | ||
| file: suite.file, | ||
| testCount: suite.tests.length, | ||
| tests: suite.tests.map(test => ({ | ||
| title: test.title, | ||
| fullTitle: test.fullTitle(), | ||
| })), | ||
| }) | ||
| } | ||
|
|
||
| // Format each suite as a readable text block | ||
| const formattedText = suites | ||
| .map(suite => { | ||
| const testList = suite.tests.map(test => ` - ${test.title}`).join('\n') | ||
| return [`Suite: ${suite.title}`, `File: ${suite.file}`, `Tests (${suite.testCount}):`, testList, '---'].join('\n') | ||
| }) | ||
| .join('\n\n') | ||
|
|
||
| return { | ||
| content: [{ type: 'text', text: formattedText }], | ||
| } | ||
| }) | ||
|
|
||
| // // Convert Resource: actions | ||
| // server.tool("list-actions", | ||
| // { }, | ||
| // async () => { | ||
| // const helpers = container.helpers(); | ||
| // const supportI = container.support('I'); | ||
| // const actions = []; | ||
|
|
||
| // // Get actions from helpers | ||
| // for (const name in helpers) { | ||
| // const helper = helpers[name]; | ||
| // methodsOfObject(helper).forEach(action => { | ||
| // const params = getParamsToString(helper[action]); | ||
| // actions.push({ | ||
| // name: action, | ||
| // source: name, | ||
| // params, | ||
| // type: 'helper' | ||
| // }); | ||
| // }); | ||
| // } | ||
|
|
||
| // // Get actions from I | ||
| // for (const name in supportI) { | ||
| // if (actions.some(a => a.name === name)) { | ||
| // continue; | ||
| // } | ||
| // const actor = supportI[name]; | ||
| // const params = getParamsToString(actor); | ||
| // actions.push({ | ||
| // name, | ||
| // source: 'I', | ||
| // params, | ||
| // type: 'support' | ||
| // }); | ||
| // } | ||
|
|
||
| // // Format actions as a readable text list | ||
| // const helperActions = actions.filter(a => a.type === 'helper') | ||
| // .sort((a, b) => a.source === b.source ? a.name.localeCompare(b.name) : a.source.localeCompare(b.source)); | ||
|
|
||
| // const supportActions = actions.filter(a => a.type === 'support') | ||
| // .sort((a, b) => a.name.localeCompare(b.name)); | ||
|
|
||
| // // Create formatted text output | ||
| // const formattedText = [ | ||
| // '# Helper Actions', | ||
| // ...helperActions.map(a => `${a.source}.${a.name}(${a.params})`), | ||
| // '', | ||
| // '# Support Actions', | ||
| // ...supportActions.map(a => `I.${a.name}(${a.params})`) | ||
| // ].join('\n'); | ||
|
|
||
| // return { | ||
| // content: [{ type: "text", text: formattedText }] | ||
| // }; | ||
| // } | ||
| // ); | ||
| // Start MCP server using stdio transport | ||
| const transport = new StdioServerTransport() | ||
| await server.connect(transport) | ||
| } | ||
|
|
||
| // Start the server without nested error handling | ||
| startServer().catch(err => { | ||
| console.error(err) | ||
| process.exit(1) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||
| # CodeceptJS Model Context Protocol (MCP) Integration | ||||||
|
|
||||||
| CodeceptJS supports the Model Context Protocol (MCP) for IDE integration, particularly with Cursor. | ||||||
|
|
||||||
| ## Using with Cursor | ||||||
|
|
||||||
| To use CodeceptJS with Cursor: | ||||||
|
|
||||||
| 1. Start the MCP server directly using the standalone executable: | ||||||
|
|
||||||
| ```bash | ||||||
| npx codecept-mcp | ||||||
| ``` | ||||||
|
|
||||||
| or | ||||||
|
|
||||||
| ```bash | ||||||
| node bin/codecept-mcp.js [path] | ||||||
| ``` | ||||||
|
|
||||||
| Where `[path]` is optional and points to your CodeceptJS project (defaults to current directory). | ||||||
|
|
||||||
| 2. In Cursor, connect to the MCP server by selecting "Connect to MCP Server" and choose "CodeceptJS" from the list. | ||||||
|
|
||||||
| ## Available Tools | ||||||
|
|
||||||
| The server provides these tools: | ||||||
|
|
||||||
| - `list-tests`: List all availble tests | ||||||
|
||||||
| - `list-tests`: List all availble tests | |
| - `list-tests`: List all available tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.