Skip to main content
Glama

create_sample_file

Generate sample files for testing purposes with a specified filename using the MCP server, ensuring secure and controlled file creation in restricted directories.

Instructions

サンプルファイルを作成します(テスト用)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNo作成するファイル名(デフォルト: sample.txt)

Implementation Reference

  • The handler function that implements the create_sample_file tool. It creates a sample file with predefined content in the current working directory after validating the path using PathValidator.
    private async createSampleFile(filename?: string): Promise<CallToolResult> { const sampleFilename = filename || "sample.txt"; try { // 現在のワーキングディレクトリにサンプルファイルを作成 const fullPath = path.resolve(process.cwd(), sampleFilename); const pathValidation = this.pathValidator.validatePath(fullPath); if (!pathValidation.isValid) { throw new Error(pathValidation.error); } console.error(`Creating sample file: ${pathValidation.normalizedPath}`); const sampleContent = `# サンプルファイル 作成日時: ${new Date().toLocaleString("ja-JP")} これは MCP サーバによって作成されたサンプルファイルです。 ## 内容 - MCP (Model Context Protocol) のテスト - ClaudeDesktop との連携確認 - ファイル操作の動作確認 - セキュリティ制限付きパスアクセス ## システム情報 - Node.js バージョン: ${process.version} - プラットフォーム: ${os.platform()} - アーキテクチャ: ${os.arch()} ## セキュリティ設定 - パスアクセス制限: 有効 - 許可されたディレクトリのみアクセス可能 Happy coding! 🚀 `; await fs.writeFile(pathValidation.normalizedPath, sampleContent, "utf-8"); return { content: [ { type: "text", text: `サンプルファイル "${pathValidation.normalizedPath}" を作成しました!\n\n内容:\n${sampleContent}`, }, ], isError: false, }; } catch (error) { throw new Error(`サンプルファイルの作成に失敗: ${error}`); } }
  • The input schema definition for the create_sample_file tool, specifying the optional filename parameter.
    inputSchema: { type: "object", properties: { filename: { type: "string", description: "作成するファイル名(デフォルト: sample.txt)", }, }, },
  • src/index.ts:169-181 (registration)
    The tool registration in the TOOLS array, including name, description, and input schema.
    { name: "create_sample_file", description: "サンプルファイルを作成します(テスト用)", inputSchema: { type: "object", properties: { filename: { type: "string", description: "作成するファイル名(デフォルト: sample.txt)", }, }, }, },
  • src/index.ts:290-292 (registration)
    The switch case in the CallToolRequestSchema handler that dispatches to the createSampleFile handler.
    case "create_sample_file": return await this.createSampleFile(args.filename as string);

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/p-united/mcpSample'

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