@gitpagedocs/mcp 1.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/package.json +33 -0
- package/src/bin.ts +8 -0
- package/src/context.ts +102 -0
- package/src/gather.ts +54 -0
- package/src/index.ts +7 -0
- package/src/resources/register-resources.ts +54 -0
- package/src/result.ts +34 -0
- package/src/server.ts +21 -0
- package/src/start.ts +9 -0
- package/src/tools/register-ai.ts +73 -0
- package/src/tools/register-docs.ts +99 -0
- package/src/tools/register-filesystem.ts +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @gitpagedocs/mcp
|
|
2
|
+
|
|
3
|
+
The **Model Context Protocol server** for [Git Page Docs](../README.md). It exposes repository-analysis and AI documentation capabilities to MCP clients (editors, agents), delegating all logic to [`@gitpagedocs/tools`](../tools/README.md). Built on `@modelcontextprotocol/sdk` + `zod`. Ships TypeScript source; run via `tsx`.
|
|
4
|
+
|
|
5
|
+
## Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gitpagedocs mcp start # via the published CLI (stdio transport)
|
|
9
|
+
# or directly:
|
|
10
|
+
node --import tsx mcp/src/index.ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Provider API keys are read from environment variables (per-provider) plus an optional `.gitpagedocs-mcp.json` selection file.
|
|
14
|
+
|
|
15
|
+
## Tools (20)
|
|
16
|
+
|
|
17
|
+
- **Filesystem:** `list_files`, `read_file`, `write_file`, `search_project`
|
|
18
|
+
- **AI:** `list_ai_providers`, `list_ai_models`, `configure_ai_provider`, `ask_ai`
|
|
19
|
+
- **Docs + analysis:** `generate_documentation`, `generate_api_docs`, `generate_architecture_docs`, `generate_database_docs`, `generate_readme`, `generate_changelog`, `generate_release_notes`, `update_documentation` (marker-patch), `validate_docs`, `analyze_repository`, `analyze_project`, `analyze_source_code`
|
|
20
|
+
|
|
21
|
+
## Resources (7)
|
|
22
|
+
|
|
23
|
+
`project://structure` · `project://docs` · `project://config` · `project://repository` · `project://readme` · `project://ai/providers` · `project://ai/models`
|
|
24
|
+
|
|
25
|
+
## Tests
|
|
26
|
+
|
|
27
|
+
In-process Client↔Server integration + E2E in `mcp/tests/**` and `mcp/smoke/mcp-selftest.ts`. Run from the repo root: `npm run smoke:mcp` and `npx vitest run`.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gitpagedocs/mcp",
|
|
3
|
+
"version": "1.1.44",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Model Context Protocol server for Git Page Docs (delegates to @gitpagedocs/tools). Ships TypeScript source; run via tsx.",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@gitpagedocs/tools": "workspace:*",
|
|
20
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
21
|
+
"zod": "^3.23.8"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Vidigal-code/git-page-docs.git",
|
|
26
|
+
"directory": "mcp"
|
|
27
|
+
},
|
|
28
|
+
"author": "Vidigal-code",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/bin.ts
ADDED
package/src/context.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import {
|
|
5
|
+
FileService,
|
|
6
|
+
GitPageDocsConfigLoader,
|
|
7
|
+
CatalogModelRegistry,
|
|
8
|
+
createDefaultFactory,
|
|
9
|
+
PROVIDER_CATALOG,
|
|
10
|
+
ConfigurationError,
|
|
11
|
+
ProviderError,
|
|
12
|
+
type AiProviderId,
|
|
13
|
+
type AIProvider,
|
|
14
|
+
type ProviderConfig,
|
|
15
|
+
} from "@gitpagedocs/tools";
|
|
16
|
+
|
|
17
|
+
const ENV_KEYS: Record<AiProviderId, string[]> = {
|
|
18
|
+
openai: ["OPENAI_API_KEY"],
|
|
19
|
+
anthropic: ["ANTHROPIC_API_KEY", "CLAUDE_API_KEY"],
|
|
20
|
+
gemini: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
|
|
21
|
+
openrouter: ["OPENROUTER_API_KEY"],
|
|
22
|
+
ollama: [],
|
|
23
|
+
"azure-openai": ["AZURE_OPENAI_API_KEY"],
|
|
24
|
+
mistral: ["MISTRAL_API_KEY"],
|
|
25
|
+
deepseek: ["DEEPSEEK_API_KEY"],
|
|
26
|
+
cohere: ["COHERE_API_KEY"],
|
|
27
|
+
groq: ["GROQ_API_KEY"],
|
|
28
|
+
xai: ["XAI_API_KEY"],
|
|
29
|
+
together: ["TOGETHER_API_KEY"],
|
|
30
|
+
fireworks: ["FIREWORKS_API_KEY"],
|
|
31
|
+
perplexity: ["PERPLEXITY_API_KEY"],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const SELECTION_FILE = ".gitpagedocs-mcp.json";
|
|
35
|
+
|
|
36
|
+
interface ProviderSelection {
|
|
37
|
+
provider: AiProviderId;
|
|
38
|
+
model?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Shared services for every MCP tool/resource. Holds no secrets. */
|
|
42
|
+
export class ServerContext {
|
|
43
|
+
readonly files: FileService;
|
|
44
|
+
readonly models = new CatalogModelRegistry();
|
|
45
|
+
readonly configLoader = new GitPageDocsConfigLoader();
|
|
46
|
+
private readonly factory = createDefaultFactory();
|
|
47
|
+
|
|
48
|
+
constructor(readonly root: string = process.cwd()) {
|
|
49
|
+
this.files = new FileService(root);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async loadSelection(): Promise<ProviderSelection> {
|
|
53
|
+
const file = path.join(this.root, SELECTION_FILE);
|
|
54
|
+
if (existsSync(file)) {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(await readFile(file, "utf8")) as ProviderSelection;
|
|
57
|
+
} catch {
|
|
58
|
+
/* fall through to default */
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { provider: "openai" };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async saveSelection(selection: ProviderSelection): Promise<void> {
|
|
65
|
+
await writeFile(path.join(this.root, SELECTION_FILE), JSON.stringify(selection, null, 2), "utf8");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private resolveKey(providerId: AiProviderId): string | undefined {
|
|
69
|
+
for (const name of ENV_KEYS[providerId]) {
|
|
70
|
+
const value = process.env[name];
|
|
71
|
+
if (value) return value;
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Build a provider + config, resolving the API key from the environment. */
|
|
77
|
+
async resolveProvider(
|
|
78
|
+
providerId?: AiProviderId,
|
|
79
|
+
model?: string,
|
|
80
|
+
): Promise<{ provider: AIProvider; config: ProviderConfig }> {
|
|
81
|
+
const selection = await this.loadSelection();
|
|
82
|
+
const id = providerId ?? selection.provider;
|
|
83
|
+
if (!PROVIDER_CATALOG[id]) throw new ConfigurationError(`Unknown AI provider: ${id}`);
|
|
84
|
+
const spec = PROVIDER_CATALOG[id];
|
|
85
|
+
const apiKey = this.resolveKey(id);
|
|
86
|
+
if (spec.auth !== "none" && !apiKey) {
|
|
87
|
+
throw new ProviderError(
|
|
88
|
+
`No API key for ${spec.label}. Set ${ENV_KEYS[id].join(" or ")} in the environment.`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const baseUrl =
|
|
92
|
+
id === "ollama"
|
|
93
|
+
? process.env.OLLAMA_BASE_URL
|
|
94
|
+
: id === "azure-openai"
|
|
95
|
+
? process.env.AZURE_OPENAI_BASE_URL
|
|
96
|
+
: undefined;
|
|
97
|
+
return {
|
|
98
|
+
provider: this.factory.create(id),
|
|
99
|
+
config: { providerId: id, model: model ?? selection.model ?? spec.defaultModel, apiKey, baseUrl },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/gather.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import type { ServerContext } from "./context";
|
|
3
|
+
|
|
4
|
+
const MAX_CONTEXT = 24_000;
|
|
5
|
+
|
|
6
|
+
function clamp(text: string): string {
|
|
7
|
+
return text.length > MAX_CONTEXT ? `${text.slice(0, MAX_CONTEXT)}\n…[truncated]` : text;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function repoListing(ctx: ServerContext): Promise<string> {
|
|
11
|
+
const files = await ctx.files.list(".", { recursive: true, maxEntries: 400 });
|
|
12
|
+
return `Project files:\n${files.join("\n")}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function fileContext(ctx: ServerContext, path: string): Promise<string> {
|
|
16
|
+
return clamp(`File: ${path}\n\n${await ctx.files.read(path)}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function packageContext(ctx: ServerContext): Promise<string> {
|
|
20
|
+
try {
|
|
21
|
+
return `package.json:\n${await ctx.files.read("package.json")}`;
|
|
22
|
+
} catch {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function gitLog(ctx: ServerContext, count = 50): string {
|
|
28
|
+
try {
|
|
29
|
+
const out = execSync(`git log --oneline -n ${count}`, {
|
|
30
|
+
cwd: ctx.root,
|
|
31
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
32
|
+
}).toString();
|
|
33
|
+
return out.trim() ? `Recent commits:\n${out.trim()}` : "";
|
|
34
|
+
} catch {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function docsContext(ctx: ServerContext, dir = "."): Promise<string> {
|
|
40
|
+
const files = (await ctx.files.list(dir, { recursive: true, maxEntries: 2000 })).filter((f) =>
|
|
41
|
+
/\.(md|markdown|mdx)$/i.test(f),
|
|
42
|
+
);
|
|
43
|
+
const parts: string[] = [];
|
|
44
|
+
for (const file of files.slice(0, 40)) {
|
|
45
|
+
try {
|
|
46
|
+
parts.push(`### ${file}\n${await ctx.files.read(file, 40_000)}`);
|
|
47
|
+
} catch {
|
|
48
|
+
/* skip unreadable */
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return clamp(parts.join("\n\n"));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { clamp };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @gitpagedocs/mcp — Model Context Protocol server for Git Page Docs.
|
|
2
|
+
//
|
|
3
|
+
// Tools and resources are thin: they delegate to @gitpagedocs/tools (the shared
|
|
4
|
+
// core). Launch with `gitpagedocs mcp start` or the bin entry.
|
|
5
|
+
export { createServer, SERVER_INFO } from "./server";
|
|
6
|
+
export { startMcpServer } from "./start";
|
|
7
|
+
export { ServerContext } from "./context";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { PROVIDER_CATALOG, ALL_PROVIDER_IDS } from "@gitpagedocs/tools";
|
|
3
|
+
import type { ServerContext } from "../context";
|
|
4
|
+
import { repoListing, docsContext, packageContext } from "../gather";
|
|
5
|
+
|
|
6
|
+
/** Read-only project resources exposed over the MCP `project://` scheme. */
|
|
7
|
+
export function registerResources(server: McpServer, ctx: ServerContext): void {
|
|
8
|
+
const def = (
|
|
9
|
+
name: string,
|
|
10
|
+
uri: string,
|
|
11
|
+
description: string,
|
|
12
|
+
mimeType: string,
|
|
13
|
+
read: () => Promise<string>,
|
|
14
|
+
): void => {
|
|
15
|
+
server.registerResource(name, uri, { description, mimeType }, async (u) => {
|
|
16
|
+
let body: string;
|
|
17
|
+
try {
|
|
18
|
+
body = await read();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
body = `Unavailable: ${String(error)}`;
|
|
21
|
+
}
|
|
22
|
+
return { contents: [{ uri: u.href, mimeType, text: body }] };
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
def("structure", "project://structure", "Recursive project file tree.", "text/plain", () =>
|
|
27
|
+
repoListing(ctx),
|
|
28
|
+
);
|
|
29
|
+
def("docs", "project://docs", "Concatenated project Markdown documentation.", "text/markdown", () =>
|
|
30
|
+
docsContext(ctx),
|
|
31
|
+
);
|
|
32
|
+
def("config", "project://config", "Resolved gitpagedocs configuration.", "application/json", async () => {
|
|
33
|
+
const { config, sourcePath } = await ctx.configLoader.loadGitPageDocsConfig(ctx.root);
|
|
34
|
+
return JSON.stringify({ sourcePath, config }, null, 2);
|
|
35
|
+
});
|
|
36
|
+
def("repository", "project://repository", "Repository metadata (package.json).", "text/plain", () =>
|
|
37
|
+
packageContext(ctx),
|
|
38
|
+
);
|
|
39
|
+
def("readme", "project://readme", "Project README.", "text/markdown", () => ctx.files.read("README.md"));
|
|
40
|
+
def("ai-providers", "project://ai/providers", "Available AI providers.", "application/json", async () =>
|
|
41
|
+
JSON.stringify(
|
|
42
|
+
ALL_PROVIDER_IDS.map((id) => ({ id, label: PROVIDER_CATALOG[id].label, defaultModel: PROVIDER_CATALOG[id].defaultModel })),
|
|
43
|
+
null,
|
|
44
|
+
2,
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
def("ai-models", "project://ai/models", "Catalog models per provider.", "application/json", async () =>
|
|
48
|
+
JSON.stringify(
|
|
49
|
+
ALL_PROVIDER_IDS.map((id) => ({ provider: id, models: ctx.models.list(id).map((m) => m.id) })),
|
|
50
|
+
null,
|
|
51
|
+
2,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}
|
package/src/result.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isAppError } from "@gitpagedocs/tools";
|
|
2
|
+
|
|
3
|
+
export interface TextResult {
|
|
4
|
+
// Index signature matches the MCP SDK CallToolResult shape.
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
content: Array<{ type: "text"; text: string }>;
|
|
7
|
+
isError?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function text(value: string): TextResult {
|
|
11
|
+
return { content: [{ type: "text", text: value }] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function json(value: unknown): TextResult {
|
|
15
|
+
return text(JSON.stringify(value, null, 2));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function errorResult(error: unknown): TextResult {
|
|
19
|
+
const message = isAppError(error) ? `${error.code}: ${error.message}` : String(error);
|
|
20
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Wrap a tool handler so thrown errors become structured isError results. */
|
|
24
|
+
export function safe<TArgs>(
|
|
25
|
+
handler: (args: TArgs) => Promise<TextResult>,
|
|
26
|
+
): (args: TArgs) => Promise<TextResult> {
|
|
27
|
+
return async (args: TArgs) => {
|
|
28
|
+
try {
|
|
29
|
+
return await handler(args);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return errorResult(error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { ServerContext } from "./context";
|
|
3
|
+
import { registerFilesystemTools } from "./tools/register-filesystem";
|
|
4
|
+
import { registerAiTools } from "./tools/register-ai";
|
|
5
|
+
import { registerDocsTools } from "./tools/register-docs";
|
|
6
|
+
import { registerResources } from "./resources/register-resources";
|
|
7
|
+
|
|
8
|
+
export const SERVER_INFO = { name: "gitpagedocs-mcp", version: "0.1.0" } as const;
|
|
9
|
+
|
|
10
|
+
/** Build the MCP server with every tool and resource registered. */
|
|
11
|
+
export function createServer(root: string = process.cwd()): McpServer {
|
|
12
|
+
const server = new McpServer(SERVER_INFO);
|
|
13
|
+
const ctx = new ServerContext(root);
|
|
14
|
+
|
|
15
|
+
registerFilesystemTools(server, ctx);
|
|
16
|
+
registerAiTools(server, ctx);
|
|
17
|
+
registerDocsTools(server, ctx);
|
|
18
|
+
registerResources(server, ctx);
|
|
19
|
+
|
|
20
|
+
return server;
|
|
21
|
+
}
|
package/src/start.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
2
|
+
import { createServer } from "./server";
|
|
3
|
+
|
|
4
|
+
/** Start the MCP server over stdio. Resolves when the transport closes. */
|
|
5
|
+
export async function startMcpServer(root: string = process.cwd()): Promise<void> {
|
|
6
|
+
const server = createServer(root);
|
|
7
|
+
const transport = new StdioServerTransport();
|
|
8
|
+
await server.connect(transport);
|
|
9
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { PROVIDER_CATALOG, ALL_PROVIDER_IDS, type AiProviderId } from "@gitpagedocs/tools";
|
|
4
|
+
import type { ServerContext } from "../context";
|
|
5
|
+
import { json, text, safe } from "../result";
|
|
6
|
+
|
|
7
|
+
const providerEnum = z.enum(ALL_PROVIDER_IDS as [AiProviderId, ...AiProviderId[]]);
|
|
8
|
+
|
|
9
|
+
/** AI provider/model info, configuration, and one-shot generation. */
|
|
10
|
+
export function registerAiTools(server: McpServer, ctx: ServerContext): void {
|
|
11
|
+
server.registerTool(
|
|
12
|
+
"list_ai_providers",
|
|
13
|
+
{ description: "List the available AI providers with their default models and capabilities." },
|
|
14
|
+
safe(async () =>
|
|
15
|
+
json(
|
|
16
|
+
ALL_PROVIDER_IDS.map((id) => ({
|
|
17
|
+
id,
|
|
18
|
+
label: PROVIDER_CATALOG[id].label,
|
|
19
|
+
defaultModel: PROVIDER_CATALOG[id].defaultModel,
|
|
20
|
+
capabilities: PROVIDER_CATALOG[id].capabilities,
|
|
21
|
+
})),
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
server.registerTool(
|
|
27
|
+
"list_ai_models",
|
|
28
|
+
{
|
|
29
|
+
description: "List the catalog models for a provider (or all providers).",
|
|
30
|
+
inputSchema: { provider: providerEnum.optional() },
|
|
31
|
+
},
|
|
32
|
+
safe(async ({ provider }) => {
|
|
33
|
+
const ids = provider ? [provider] : ALL_PROVIDER_IDS;
|
|
34
|
+
return json(ids.map((id) => ({ provider: id, models: ctx.models.list(id).map((m) => m.id) })));
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
server.registerTool(
|
|
39
|
+
"configure_ai_provider",
|
|
40
|
+
{
|
|
41
|
+
description: "Set the default AI provider/model for this project (non-secret; keys come from env).",
|
|
42
|
+
inputSchema: {
|
|
43
|
+
provider: providerEnum,
|
|
44
|
+
model: z.string().optional(),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
safe(async ({ provider, model }) => {
|
|
48
|
+
await ctx.saveSelection({ provider, model });
|
|
49
|
+
return text(`Default provider set to ${provider}${model ? ` (${model})` : ""}.`);
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
server.registerTool(
|
|
54
|
+
"ask_ai",
|
|
55
|
+
{
|
|
56
|
+
description: "Ask the configured AI provider a question and return its answer.",
|
|
57
|
+
inputSchema: {
|
|
58
|
+
prompt: z.string().describe("The user prompt."),
|
|
59
|
+
provider: providerEnum.optional(),
|
|
60
|
+
model: z.string().optional(),
|
|
61
|
+
system: z.string().optional().describe("Optional system instruction."),
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
safe(async ({ prompt, provider, model, system }) => {
|
|
65
|
+
const { provider: impl, config } = await ctx.resolveProvider(provider, model);
|
|
66
|
+
const response = await impl.generate(
|
|
67
|
+
{ system, messages: [{ role: "user", content: prompt }], temperature: 0.3 },
|
|
68
|
+
config,
|
|
69
|
+
);
|
|
70
|
+
return text(response.text);
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { DocumentationService, patchManagedRegion, type DocKind, type AiProviderId } from "@gitpagedocs/tools";
|
|
4
|
+
import type { ServerContext } from "../context";
|
|
5
|
+
import { text, safe } from "../result";
|
|
6
|
+
import { repoListing, fileContext, packageContext, gitLog, docsContext } from "../gather";
|
|
7
|
+
|
|
8
|
+
async function generate(
|
|
9
|
+
ctx: ServerContext,
|
|
10
|
+
kind: DocKind,
|
|
11
|
+
context: string,
|
|
12
|
+
instructions?: string,
|
|
13
|
+
provider?: AiProviderId,
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
const { provider: impl, config } = await ctx.resolveProvider(provider);
|
|
16
|
+
const service = new DocumentationService(impl, config);
|
|
17
|
+
return service.generate({ kind, context, instructions });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const providerOpt = z.string().optional().describe("Override the configured AI provider id.");
|
|
21
|
+
|
|
22
|
+
/** Documentation generators and analyzers (AI-backed, delegating to tools). */
|
|
23
|
+
export function registerDocsTools(server: McpServer, ctx: ServerContext): void {
|
|
24
|
+
const def = (
|
|
25
|
+
name: string,
|
|
26
|
+
description: string,
|
|
27
|
+
kind: DocKind,
|
|
28
|
+
gather: (args: { path?: string }) => Promise<string>,
|
|
29
|
+
withPath = false,
|
|
30
|
+
): void => {
|
|
31
|
+
server.registerTool(
|
|
32
|
+
name,
|
|
33
|
+
{
|
|
34
|
+
description,
|
|
35
|
+
inputSchema: withPath
|
|
36
|
+
? { path: z.string().describe("Relative file path."), provider: providerOpt }
|
|
37
|
+
: { provider: providerOpt },
|
|
38
|
+
},
|
|
39
|
+
safe(async (args: { path?: string; provider?: string }) =>
|
|
40
|
+
text(await generate(ctx, kind, await gather(args), undefined, args.provider as AiProviderId | undefined)),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
def("generate_documentation", "Generate developer documentation for a source file.", "documentation",
|
|
46
|
+
({ path }) => fileContext(ctx, path as string), true);
|
|
47
|
+
def("generate_api_docs", "Generate API reference docs for a file.", "api",
|
|
48
|
+
({ path }) => fileContext(ctx, path as string), true);
|
|
49
|
+
def("generate_database_docs", "Generate data-model documentation for a file.", "database",
|
|
50
|
+
({ path }) => fileContext(ctx, path as string), true);
|
|
51
|
+
def("analyze_source_code", "Analyze a source file: responsibilities, issues, suggestions.", "analyze-source",
|
|
52
|
+
({ path }) => fileContext(ctx, path as string), true);
|
|
53
|
+
|
|
54
|
+
def("generate_readme", "Generate a README from the repository.", "readme",
|
|
55
|
+
async () => `${await repoListing(ctx)}\n\n${await packageContext(ctx)}`);
|
|
56
|
+
def("generate_architecture_docs", "Generate architecture documentation for the repository.", "architecture",
|
|
57
|
+
() => repoListing(ctx));
|
|
58
|
+
def("analyze_repository", "Analyze the repository structure and stack.", "analyze-repository",
|
|
59
|
+
() => repoListing(ctx));
|
|
60
|
+
def("analyze_project", "Analyze the project: architecture, dependencies, risks.", "analyze-project",
|
|
61
|
+
async () => `${await repoListing(ctx)}\n\n${await packageContext(ctx)}`);
|
|
62
|
+
def("generate_changelog", "Generate a CHANGELOG from recent commits.", "changelog",
|
|
63
|
+
async () => gitLog(ctx, 80) || (await repoListing(ctx)));
|
|
64
|
+
def("generate_release_notes", "Generate release notes from recent commits.", "release-notes",
|
|
65
|
+
async () => gitLog(ctx, 80) || (await repoListing(ctx)));
|
|
66
|
+
def("validate_docs", "Review docs for accuracy, completeness and broken references.", "validate",
|
|
67
|
+
() => docsContext(ctx));
|
|
68
|
+
|
|
69
|
+
// update_documentation patches the managed region of an existing file.
|
|
70
|
+
server.registerTool(
|
|
71
|
+
"update_documentation",
|
|
72
|
+
{
|
|
73
|
+
description: "Regenerate and patch the managed region of a documentation file (preserves manual content).",
|
|
74
|
+
inputSchema: {
|
|
75
|
+
path: z.string().describe("Target documentation file."),
|
|
76
|
+
instructions: z.string().optional().describe("What to update."),
|
|
77
|
+
provider: providerOpt,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
safe(async ({ path, instructions, provider }) => {
|
|
81
|
+
let existing = "";
|
|
82
|
+
try {
|
|
83
|
+
existing = await ctx.files.read(path);
|
|
84
|
+
} catch {
|
|
85
|
+
existing = "";
|
|
86
|
+
}
|
|
87
|
+
const generated = await generate(
|
|
88
|
+
ctx,
|
|
89
|
+
"update",
|
|
90
|
+
`Existing file:\n${existing}`,
|
|
91
|
+
instructions,
|
|
92
|
+
provider as AiProviderId | undefined,
|
|
93
|
+
);
|
|
94
|
+
const patched = patchManagedRegion(existing, generated);
|
|
95
|
+
const written = await ctx.files.write(path, patched.content);
|
|
96
|
+
return text(`Updated ${written} (${patched.replaced ? "replaced" : "appended"} managed region).`);
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { ServerContext } from "../context";
|
|
4
|
+
import { json, text, safe } from "../result";
|
|
5
|
+
|
|
6
|
+
/** Filesystem tools — root-bounded, delegating to tools FileService. */
|
|
7
|
+
export function registerFilesystemTools(server: McpServer, ctx: ServerContext): void {
|
|
8
|
+
server.registerTool(
|
|
9
|
+
"list_files",
|
|
10
|
+
{
|
|
11
|
+
description: "List files and directories within the project (root-bounded).",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
path: z.string().optional().describe("Relative directory (default: project root)."),
|
|
14
|
+
recursive: z.boolean().optional().describe("Recurse into subdirectories."),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
safe(async ({ path, recursive }) => json(await ctx.files.list(path ?? ".", { recursive: recursive ?? false }))),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
server.registerTool(
|
|
21
|
+
"read_file",
|
|
22
|
+
{
|
|
23
|
+
description: "Read a UTF-8 text file from the project.",
|
|
24
|
+
inputSchema: { path: z.string().describe("Relative file path.") },
|
|
25
|
+
},
|
|
26
|
+
safe(async ({ path }) => text(await ctx.files.read(path))),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
server.registerTool(
|
|
30
|
+
"write_file",
|
|
31
|
+
{
|
|
32
|
+
description: "Write a UTF-8 text file in the project (creates directories as needed).",
|
|
33
|
+
inputSchema: {
|
|
34
|
+
path: z.string().describe("Relative file path."),
|
|
35
|
+
content: z.string().describe("Full file content."),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
safe(async ({ path, content }) => text(`Wrote ${await ctx.files.write(path, content)}`)),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
server.registerTool(
|
|
42
|
+
"search_project",
|
|
43
|
+
{
|
|
44
|
+
description: "Search project text files for a substring; returns file/line matches.",
|
|
45
|
+
inputSchema: {
|
|
46
|
+
query: z.string().describe("Text to search for."),
|
|
47
|
+
extension: z.string().optional().describe('Limit to files ending with this (e.g. ".ts").'),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
safe(async ({ query, extension }) => json(await ctx.files.search(query, { extension }))),
|
|
51
|
+
);
|
|
52
|
+
}
|