test-mcp.js•1.64 kB
#!/usr/bin/env node
/**
* Simple test script to verify the MCP server can be instantiated
* and list its tools correctly
*/
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import dotenv from "dotenv";
dotenv.config();
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
if (!GEMINI_API_KEY) {
console.error("❌ Error: GEMINI_API_KEY not found in environment");
process.exit(1);
}
console.log("✓ API key found");
const server = new Server(
{
name: "gemini-image-mcp-server",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: "generate_image",
description: "Generate or edit images using Gemini 2.5 Flash Image",
inputSchema: {
type: "object",
properties: {
prompt: { type: "string" },
output_path: { type: "string" },
},
required: ["prompt", "output_path"],
},
},
],
}));
console.log("✓ Server created successfully");
console.log("✓ Tool handlers registered");
console.log("✓ Server configuration valid");
console.log("\n✅ MCP server validation passed!");
console.log("\nServer is ready to use. Configure it in your MCP client settings.");
console.log("\nTo add to Claude Code, add this to your MCP settings:");
console.log(JSON.stringify({
"gemini-image": {
"command": "node",
"args": [process.cwd() + "/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here"
}
}
}, null, 2));