MCPcopy
hub / github.com/benborla/mcp-server-mysql / createMcpServer

Function createMcpServer

index.ts:143–433  ·  view source on GitHub ↗
({
  sessionId,
  config,
}: {
  sessionId?: string;
  config: z.infer<typeof configSchema>;
})

Source from the content-addressed store, hash-verified

141
142// Export the default function that creates and returns the MCP server
143export default function createMcpServer({
144 sessionId,
145 config,
146}: {
147 sessionId?: string;
148 config: z.infer<typeof configSchema>;
149}) {
150 // Create the server instance
151 const server = new Server(
152 {
153 name: "MySQL MCP Server",
154 version: process.env.npm_package_version || "1.0.0",
155 },
156 {
157 capabilities: {
158 resources: {},
159 tools: {
160 mysql_query: {
161 description: toolDescription,
162 inputSchema: {
163 type: "object",
164 properties: {
165 sql: {
166 type: "string",
167 description: "The SQL query to execute",
168 },
169 },
170 required: ["sql"],
171 },
172 annotations: {
173 readOnlyHint: isReadOnly,
174 idempotentHint: isReadOnly,
175 destructiveHint: !isReadOnly,
176 openWorldHint: false,
177 title: "MySQL Query",
178 },
179 },
180 },
181 },
182 },
183 );
184
185 // Register request handlers for resources
186 server.setRequestHandler(ListResourcesRequestSchema, async () => {
187 try {
188 log("info", "Handling ListResourcesRequest");
189 const connectionInfo = process.env.MYSQL_SOCKET_PATH
190 ? `socket: ${process.env.MYSQL_SOCKET_PATH}`
191 : `host: ${process.env.MYSQL_HOST || "localhost"}, port: ${
192 process.env.MYSQL_PORT || 3306
193 }`;
194 log("info", `Connection info: ${connectionInfo}`);
195
196 // Query to get all tables
197 const tablesQuery = `
198 SELECT
199 table_name as name,
200 table_schema as \`database\`,

Callers 1

index.tsFile · 0.85

Calls 7

executeQueryFunction · 0.85
isPIIColumnFunction · 0.85
executeReadOnlyQueryFunction · 0.85
getPoolFunction · 0.85
safeExitFunction · 0.85
shutdownFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected