1<?php
2
3namespace dokuwiki\plugin\mcp;
4
5use dokuwiki\Remote\OpenApiDoc\OpenAPIGenerator;
6
7/**
8 * Generate the JSON schema for MCP tools descriptions
9 *
10 * This is a thin wrapper around the OpenAPIGenerator
11 */
12class SchemaGenerator extends OpenAPIGenerator
13{
14    /**
15     * Get the list of available API calls as tools
16     *
17     * @return array
18     */
19    public function getTools()
20    {
21        $tools = [];
22
23        $methods = $this->api->getMethods();
24
25
26        $nullSchema = [
27            "type" => "object",
28            "properties" => (object)[],
29            "required" => []
30        ];
31
32        foreach ($methods as $method => $call) {
33            $args = $call->getArgs();
34
35            // Some LLMs (e.g. Claude) don't allow underscores in method names, so we replace them with dots.
36            $tools[] = [
37                'name' => str_replace('.', '_', $method),
38                'description' => $call->getDescription(),
39                'inputSchema' => $args ? $this->getMethodArguments($args)['schema'] : $nullSchema
40            ];
41        }
42
43        return $tools;
44    }
45}
46