Skip to main content
Glama

add_text_file

Add a text file to the docs directory by specifying a URL and a document name, enabling integration into the MCP Docs RAG Server for context-aware LLM queries.

Instructions

Add a text file to the docs directory with a specified name. Please do not use 'docs' in the document name.

Input Schema

NameRequiredDescriptionDefault
document_nameYesName of the document (will be used as directory name). Choose a descriptive name rather than using the URL filename (e.g. 'hono' instead of 'llms-full.txt')
file_urlYesURL of the text file to download

Input Schema (JSON Schema)

{ "properties": { "document_name": { "description": "Name of the document (will be used as directory name). Choose a descriptive name rather than using the URL filename (e.g. 'hono' instead of 'llms-full.txt')", "type": "string" }, "file_url": { "description": "URL of the text file to download", "type": "string" } }, "required": [ "file_url", "document_name" ], "type": "object" }

Implementation Reference

  • Handler for executing the 'add_text_file' tool. Validates inputs, calls downloadFile helper to add the text file as a document, and returns success or 'already exists' message.
    case "add_text_file": { const fileUrl = String(request.params.arguments?.file_url); const documentName = String(request.params.arguments?.document_name); if (!fileUrl) { throw new Error("File URL is required"); } if (!documentName) { throw new Error("Document name is required"); } const result = await downloadFile(fileUrl, documentName); // If document already exists, inform the user without updating if (result.exists) { return { content: [{ type: "text", text: `Document '${result.name}' already exists. Please use list_documents to view existing documents.` }] }; } return { content: [{ type: "text", text: `Added document '${result.name}' with content from ${fileUrl}. The index will be created when you query this document for the first time.` }] }; }
  • src/index.ts:411-428 (registration)
    Registration of the 'add_text_file' tool in the ListToolsRequestSchema handler, defining its name, description, and input schema.
    { name: "add_text_file", description: "Add a text file to the docs directory with a specified name. Please do not use 'docs' in the document name.", inputSchema: { type: "object", properties: { file_url: { type: "string", description: "URL of the text file to download" }, document_name: { type: "string", description: "Name of the document (will be used as directory name). Choose a descriptive name rather than using the URL filename (e.g. 'hono' instead of 'llms-full.txt')" } }, required: ["file_url", "document_name"] } }
  • Helper function downloadFile that implements the core logic of downloading a text file from URL to a document directory as 'index.txt', checking if already exists.
    export async function downloadFile(fileUrl: string, documentName: string): Promise<{ name: string; exists: boolean }> { // ドキュメント用のディレクトリを作成 const docDir = path.join(DOCS_PATH, documentName); // ディレクトリが存在する場合は更新せずに通知 if (fs.existsSync(docDir)) { return { name: documentName, exists: true }; } // ディレクトリが存在しない場合は作成 fs.mkdirSync(docDir, { recursive: true }); // ファイル名を取得(URLのパス部分の最後) const fileName = path.basename(fileUrl); // index.txtとしてファイルを保存 const filePath = path.join(docDir, 'index.txt'); // ファイルをダウンロード await execAsync(`cd "${docDir}" && wget -O "index.txt" ${fileUrl}`); return { name: documentName, exists: false }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kazuph/mcp-docs-rag'

If you have feedback or need assistance with the MCP directory API, please join our Discord server