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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "githits",
"description": "CLI companion for GitHits - code examples from global open source for developers and AI assistants",
"version": "0.1.1",
"version": "0.1.2",
"type": "module",
"files": [
"dist",
Expand Down
12 changes: 5 additions & 7 deletions src/commands/mcp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, spyOn } from "bun:test";
import { describe, expect, it } from "bun:test";
import type { Dependencies } from "../container.js";
import {
createMockAuthService,
Expand All @@ -7,7 +7,6 @@ import {
createMockFileSystemService,
createMockGitHitsService,
} from "../services/test-helpers.js";
import { AuthRequiredError } from "../shared/require-auth.js";
import { createMcpServer, startMcpServer } from "./mcp.js";

function createTestDeps(overrides: Partial<Dependencies> = {}): Dependencies {
Expand Down Expand Up @@ -45,12 +44,11 @@ describe("createMcpServer", () => {
});

describe("startMcpServer", () => {
it("throws AuthRequiredError on auth failure", async () => {
const consoleSpy = spyOn(console, "log").mockImplementation(() => {});
it("starts successfully without a valid token", async () => {
const deps = createTestDeps({ hasValidToken: false });

await expect(startMcpServer(deps)).rejects.toThrow(AuthRequiredError);

consoleSpy.mockRestore();
// Server should start and connect transport without throwing.
// Auth errors are deferred to individual tool calls.
await expect(startMcpServer(deps)).resolves.toBeUndefined();
});
});
21 changes: 4 additions & 17 deletions src/commands/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { Command } from "commander";
import { version } from "../../package.json";
import { createContainer, type Dependencies } from "../container.js";
import { dim, highlight, shouldUseColors } from "../shared/colors.js";
import { AuthRequiredError, requireAuth } from "../shared/require-auth.js";
import {
createFeedbackTool,
createSearchLanguageTool,
Expand Down Expand Up @@ -44,8 +43,6 @@ export function createMcpServer(deps: Dependencies): McpServer {
* Start the MCP server. Exported for testability.
*/
export async function startMcpServer(deps: Dependencies): Promise<void> {
requireAuth(deps, "to start MCP server");

const server = createMcpServer(deps);
const transport = new StdioServerTransport();
await server.connect(transport);
Expand Down Expand Up @@ -101,13 +98,8 @@ Available tools: search, search_language, feedback`,
showMcpSetupInstructions();
return;
}
try {
const deps = await createContainer();
await startMcpServer(deps);
} catch (error) {
if (error instanceof AuthRequiredError) process.exit(1);
throw error;
}
const deps = await createContainer();
await startMcpServer(deps);
});

mcpCommand
Expand All @@ -120,12 +112,7 @@ This command explicitly starts the server and is intended for use
in MCP configuration files. Use 'githits mcp' for interactive setup.`,
)
.action(async () => {
try {
const deps = await createContainer();
await startMcpServer(deps);
} catch (error) {
if (error instanceof AuthRequiredError) process.exit(1);
throw error;
}
const deps = await createContainer();
await startMcpServer(deps);
});
}