Skip to content
Merged
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
37 changes: 5 additions & 32 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
Expand All @@ -10,6 +9,7 @@ import { OpenAPI } from './src/api/client/index.js';
import * as Tools from './src/tools/index.js';
import type { ToolKeys } from './src/schemas.js';
import * as Handlers from './src/handlers/index.js';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';

// Check for API key
const CODACY_ACCOUNT_TOKEN = process.env.CODACY_ACCOUNT_TOKEN;
Expand All @@ -20,7 +20,7 @@ OpenAPI.HEADERS = {
'X-Codacy-Origin': 'mcp-server',
};

const server = new Server(
const mcpServer = new McpServer(
{
name: 'codacy-mcp-server',
version: '0.1.0',
Expand All @@ -29,33 +29,6 @@ const server = new Server(
capabilities: {
tools: {},
resources: {},
triggers: {
patterns: [
'codacy',
'code quality',
'code analysis',
'security vulnerabilities',
'repository issues',
'pull request analysis',
'code coverage',
'issues',
'security',
'srm',
'analysis',
'tool',
'pattern',
'pull request',
'repository',
'file',
'coverage',
'git',
'diff',
'branch',
'commit',
'severity',
'organization',
],
},
},
}
);
Expand Down Expand Up @@ -170,14 +143,14 @@ const toolDefinitions: { [key in ToolKeys]: ToolDefinition } = {
};

// Register tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
mcpServer.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: Object.values(toolDefinitions)
.filter(({ noAuth }) => CODACY_ACCOUNT_TOKEN || noAuth)
.map(({ tool }) => tool),
}));

// Register request handlers
server.setRequestHandler(CallToolRequestSchema, async request => {
mcpServer.server.setRequestHandler(CallToolRequestSchema, async request => {
try {
if (!request.params.arguments) {
throw new Error('Arguments are required');
Expand Down Expand Up @@ -206,7 +179,7 @@ server.setRequestHandler(CallToolRequestSchema, async request => {

async function runServer() {
const transport = new StdioServerTransport();
await server.connect(transport);
await mcpServer.connect(transport);
console.error('Codacy MCP Server running on stdio');
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"inspect": "npm run build && npx @modelcontextprotocol/inspector -e CODACY_ACCOUNT_TOKEN=$CODACY_ACCOUNT_TOKEN node dist/index.js"
},
"dependencies": {
"@modelcontextprotocol/sdk": "1.0.1",
"@modelcontextprotocol/sdk": "1.25.2",
"@types/node": "^22",
"@types/node-fetch": "^2.6.12",
"@types/sarif": "2.1.7",
Expand Down