Skip to main content
Glama
KunihiroS

claude-code-mcp

your_own_query

Send custom queries with contextual details to Claude Code MCP server for tailored responses. Ideal for precise information retrieval and specific task execution.

Instructions

Sends a custom query with context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextNoAdditional context
queryYesQuery text

Implementation Reference

  • The execution handler for the 'your_own_query' tool. It destructures the query and optional context from arguments, constructs a simple prompt, calls the shared runClaudeCommand to execute Claude CLI with '--print', and returns the text output.
    case 'your_own_query': {
      const { query, context } = args;
      logger.debug(`Processing your_own_query request, query length: ${query.length}`);
      const prompt = `Query: ${query} ${context || ''}`;
      logger.debug('Calling Claude CLI with prompt');
      const output = await runClaudeCommand(['--print'], prompt);
      logger.debug(`Received response from Claude, length: ${output.length}`);
      return { content: [{ type: 'text', text: output }] };
    }
  • Registration of the 'your_own_query' tool in the ListTools response, including its name, description, and input schema definition.
    {
      name: 'your_own_query',
      description: 'Sends a custom query with context.',
      inputSchema: {
        type: 'object',
        properties: {
          query: { type: 'string', description: 'Query text' },
          context: { type: 'string', description: 'Additional context', default: '' }
        },
        required: ['query']
      }
    }
  • Input schema for the 'your_own_query' tool, defining the expected parameters: required 'query' string and optional 'context' string.
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string', description: 'Query text' },
        context: { type: 'string', description: 'Additional context', default: '' }
      },
      required: ['query']
  • Shared helper function runClaudeCommand used by all tools, including 'your_own_query', to execute the Claude CLI binary securely with timeout and logging.
    const runClaudeCommand = (claudeArgs: string[], stdinInput?: string): Promise<string> => {
      return new Promise((resolve, reject) => {
        // タイムアウト設定 (5分)
        const timeoutMs = 5 * 60 * 1000;
        let timeoutId: NodeJS.Timeout;
        
        try {
          // より詳細なデバッグ情報
          logger.debug(`Executing Claude CLI at path: ${validatedClaudePath}`);
          logger.debug(`Claude CLI arguments: ${JSON.stringify(claudeArgs)}`);
          if (stdinInput) logger.debug(`Input length: ${stdinInput.length} characters`);
          
          // 環境変数をログに出力
          logger.debug(`Environment PATH: ${process.env.PATH}`);
          
          if (validatedClaudePath === null) {
              logger.error('validatedClaudePath is null. Claude CLI cannot be executed.');
              // エラーをクライアントに返すなど、より丁寧なエラー処理を検討してください。
              throw new Error('Validated Claude CLI path is not available. Please check CLAUDE_BIN environment variable or server configuration.');
          }
    
          const proc = child_process.spawn(validatedClaudePath, claudeArgs, {
              env: { ...process.env },
              stdio: ['pipe', 'pipe', 'pipe']
          }) as child_process.ChildProcess;
    
          // 標準入力がある場合は書き込みと終了
          if (stdinInput) {
              proc.stdin!.write(stdinInput);
              proc.stdin!.end();
              logger.debug('Wrote input to Claude CLI stdin');
          }
    
          let stdout = '';
          let stderr = '';
    
          proc.stdout!.on('data', (data: string) => {
              const chunk = data.toString();
              stdout += chunk;
              logger.debug(`Received stdout chunk: ${chunk.length} bytes`);
          });
    
          proc.stderr!.on('data', (data: string) => {
              const chunk = data.toString();
              stderr += chunk;
              logger.error(`Claude stderr: ${chunk}`);
              logger.debug(`Claude stderr output: ${chunk}`);
          });
    
          // タイムアウト設定
          timeoutId = setTimeout(() => {
              logger.error(`Command timed out after ${timeoutMs/1000} seconds`);
              logger.debug('Killing process due to timeout');
              proc.kill();
              reject(new Error(`Command timed out after ${timeoutMs / 1000} seconds`));
          }, timeoutMs);
    
          proc.on('close', (code: number) => {
              clearTimeout(timeoutId);
              logger.debug(`Claude process closed with code: ${code}`);
              if (code === 0) {
                  logger.debug(`Claude command completed successfully, output length: ${stdout.length} bytes`);
                  resolve(stdout.trim());
              }
              else {
                  logger.error(`Command failed with code ${code}`);
                  logger.debug(`stderr: ${stderr}`);
                  reject(new Error(`Command failed with code ${code}: ${stderr}`));
              }
          });
    
          proc.on('error', (err: Error) => {
              clearTimeout(timeoutId);
              logger.error("Process spawn error:", err);
              logger.debug(`Process error details: ${err.stack}`);
              reject(err);
          });
        } catch (err) {
          logger.error("Failed to spawn process:", err);
          logger.debug(`Spawn failure details: ${err instanceof Error ? err.stack : String(err)}`);
          reject(err);
        }
      });
    };
Install Server

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/KunihiroS/claude-code-mcp'

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