add prototype
This commit is contained in:
17
src/main.ts
Normal file
17
src/main.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
|
import { server } from "./outline.js";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
// Add debugging
|
||||||
|
console.error("Current working directory:", process.cwd());
|
||||||
|
console.error("__dirname:", __dirname);
|
||||||
|
|
||||||
|
const transport = new StdioServerTransport();
|
||||||
|
await server.connect(transport);
|
||||||
|
console.error("Outline MCP server is running via stdio transport");
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error("Server error:", error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
13
src/outline.ts
Normal file
13
src/outline.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { registerDocumentTools } from "./tools/document";
|
||||||
|
import { registerCollectionTools } from "./tools/collection";
|
||||||
|
|
||||||
|
// Create an MCP server
|
||||||
|
export const server = new McpServer({
|
||||||
|
name: "outline-mcp-server",
|
||||||
|
version: "1.0.0",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register tools
|
||||||
|
registerDocumentTools(server);
|
||||||
|
registerCollectionTools(server);
|
||||||
23
src/tools/collection.ts
Normal file
23
src/tools/collection.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { createOutlineClient, handleSuccess, handleError } from "./utils";
|
||||||
|
|
||||||
|
// Register collection tools
|
||||||
|
export const registerCollectionTools = (server: McpServer) => {
|
||||||
|
server.registerTool(
|
||||||
|
"collections_list",
|
||||||
|
{
|
||||||
|
title: "List Collections",
|
||||||
|
description: "List all collections in the Outline workspace",
|
||||||
|
inputSchema: {},
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
try {
|
||||||
|
const client = createOutlineClient();
|
||||||
|
const response = await client.collections.collectionsList();
|
||||||
|
return handleSuccess(response);
|
||||||
|
} catch (error) {
|
||||||
|
return handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
50
src/tools/document.ts
Normal file
50
src/tools/document.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { createOutlineClient, handleSuccess, handleError } from "./utils";
|
||||||
|
|
||||||
|
// Register document tools
|
||||||
|
export const registerDocumentTools = (server: McpServer) => {
|
||||||
|
server.registerTool(
|
||||||
|
"documents_list",
|
||||||
|
{
|
||||||
|
title: "List Documents",
|
||||||
|
description: "List all documents in the Outline workspace",
|
||||||
|
inputSchema: {},
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
try {
|
||||||
|
const client = createOutlineClient();
|
||||||
|
const response = await client.documents.documentsList();
|
||||||
|
return handleSuccess(response);
|
||||||
|
} catch (error) {
|
||||||
|
return handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
server.registerTool(
|
||||||
|
"documents_info",
|
||||||
|
{
|
||||||
|
title: "Get Document Info",
|
||||||
|
description: "Retrieve a specific document by its ID or share ID",
|
||||||
|
inputSchema: {
|
||||||
|
id: z.string().optional().describe("Document UUID or URL ID"),
|
||||||
|
shareId: z.string().optional().describe("Document share ID"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async (args) => {
|
||||||
|
try {
|
||||||
|
const client = createOutlineClient();
|
||||||
|
const response = await client.documents.documentsInfo({
|
||||||
|
documentsInfoRequest: {
|
||||||
|
id: args?.id,
|
||||||
|
shareId: args?.shareId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return handleSuccess(response);
|
||||||
|
} catch (error) {
|
||||||
|
return handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
47
src/tools/utils.ts
Normal file
47
src/tools/utils.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { Configuration } from "../gen/api/outline/runtime";
|
||||||
|
import { DocumentsApi } from "../gen/api/outline/apis/DocumentsApi";
|
||||||
|
import { CollectionsApi } from "../gen/api/outline/apis/CollectionsApi";
|
||||||
|
|
||||||
|
// Generic Outline API client factory
|
||||||
|
export const createOutlineClient = () => {
|
||||||
|
const apiKey = process.env.OUTLINE_API_KEY;
|
||||||
|
if (!apiKey) {
|
||||||
|
throw new Error("OUTLINE_API_KEY environment variable is not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = new Configuration({
|
||||||
|
basePath: process.env.OUTLINE_BASE_URL,
|
||||||
|
accessToken: () => Promise.resolve(apiKey),
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
documents: new DocumentsApi(config),
|
||||||
|
collections: new CollectionsApi(config),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generic response handler
|
||||||
|
export const handleApiResponse = (response: any) => {
|
||||||
|
return JSON.stringify(response, null, 2);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generic error response handler
|
||||||
|
export const handleError = (error: unknown) => {
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text" as const,
|
||||||
|
text: `Error: ${
|
||||||
|
error instanceof Error ? error.message : "Unknown error"
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generic success response handler
|
||||||
|
export const handleSuccess = (data: any) => {
|
||||||
|
return {
|
||||||
|
content: [{ type: "text" as const, text: handleApiResponse(data) }],
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user