Implement smoke test for clients and servers (#76)

This commit adds `tests/smoke-test.sh`, which performs a smoke test of
all clients and servers. The smoke test tests that the clients and
servers run and that list tools is called.

This commit also adds a GitHub Actions workflow to run the smoke test on
all pull requests and pushes to main.

For practicality, this commit modifies the TypeScript and Python clients
to lazily initialize the Anthropic client, thus allowing tests to skip
setting an API key. This change also provides a friendly error when
users forget to set an API key.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Alex Akimov <alexeyakimov@gmail.com>
This commit is contained in:
Jonathan Hefner 2026-02-01 03:57:45 -06:00 • committed by GitHub
commit bd27d306c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,25 +13,23 @@ import dotenv from "dotenv";
dotenv.config(); // load environment variables from .env
const ANTHROPIC_MODEL = "claude-sonnet-4-5";
const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
if (!ANTHROPIC_API_KEY) {
throw new Error("ANTHROPIC_API_KEY is not set");
}
class MCPClient {
private mcp: Client;
private anthropic: Anthropic;
private _anthropic: Anthropic | null = null;
private transport: StdioClientTransport | null = null;
private tools: Tool[] = [];
constructor() {
// Initialize Anthropic client and MCP client
this.anthropic = new Anthropic({
apiKey: ANTHROPIC_API_KEY,
});
// Initialize MCP client
this.mcp = new Client({ name: "mcp-client-cli", version: "1.0.0" });
}
private get anthropic(): Anthropic {
// Lazy-initialize Anthropic client when needed
return this._anthropic ??= new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
}
async connectToServer(serverScriptPath: string) {
/**
* Connect to an MCP server
@ -182,6 +180,17 @@ async function main() {
const mcpClient = new MCPClient();
try {
await mcpClient.connectToServer(process.argv[2]);
// Check if we have a valid API key to continue
const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) {
console.log(
"\nNo ANTHROPIC_API_KEY found. To query these tools with Claude, set your API key:"
);
console.log(" export ANTHROPIC_API_KEY=your-api-key-here");
return;
}
await mcpClient.chatLoop();
} catch (e) {
console.error("Error:", e);