mirror of
https://github.com/penpot/penpot-mcp.git
synced 2026-04-25 11:18:37 +00:00
Provide list of all API types in initial instructions
This commit is contained in:
parent
e5b5722ce6
commit
1bc309fc5a
@ -22,6 +22,8 @@ initial_instructions: |
|
||||
directly in the connected project.
|
||||
To execute code correctly, you need to understand the Penpot Plugin API. You can retrieve API documentation via
|
||||
the `penpot_api_info` tool.
|
||||
|
||||
This is the full list of types/interfaces in the Penpot API: $api_types
|
||||
|
||||
When writing code, a key object is the `penpot` object (which is of type `Penpot`):
|
||||
* `penpot.selection` provides the list of shapes the user has selected in the Penpot UI.
|
||||
|
||||
@ -116,7 +116,7 @@ export class ApiDocs {
|
||||
* Returns all available type names.
|
||||
*/
|
||||
getTypeNames(): string[] {
|
||||
return Array.from(this.apiTypes.keys());
|
||||
return Array.from(this.apiTypes.values()).map((type) => type.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -13,6 +13,7 @@ import { HighLevelOverviewTool } from "./tools/HighLevelOverviewTool";
|
||||
import { PenpotApiInfoTool } from "./tools/PenpotApiInfoTool";
|
||||
import { ExportShapeTool } from "./tools/ExportShapeTool";
|
||||
import { ReplServer } from "./ReplServer";
|
||||
import { ApiDocs } from "./ApiDocs";
|
||||
|
||||
export class PenpotMcpServer {
|
||||
private readonly logger = createLogger("PenpotMcpServer");
|
||||
@ -22,6 +23,7 @@ export class PenpotMcpServer {
|
||||
private app: any;
|
||||
public readonly pluginBridge: PluginBridge;
|
||||
private readonly replServer: ReplServer;
|
||||
private apiDocs: ApiDocs;
|
||||
|
||||
private readonly transports = {
|
||||
streamable: {} as Record<string, StreamableHTTPServerTransport>,
|
||||
@ -34,15 +36,15 @@ export class PenpotMcpServer {
|
||||
replPort: number = 4403
|
||||
) {
|
||||
this.configLoader = new ConfigurationLoader();
|
||||
this.apiDocs = new ApiDocs();
|
||||
|
||||
const instructions = this.configLoader.getInitialInstructions();
|
||||
this.server = new McpServer(
|
||||
{
|
||||
name: "penpot-mcp-server",
|
||||
version: "1.0.0",
|
||||
},
|
||||
{
|
||||
instructions: instructions,
|
||||
instructions: this.getInitialInstructions(),
|
||||
}
|
||||
);
|
||||
|
||||
@ -54,7 +56,9 @@ export class PenpotMcpServer {
|
||||
}
|
||||
|
||||
public getInitialInstructions(): string {
|
||||
return this.configLoader.getInitialInstructions();
|
||||
let instructions = this.configLoader.getInitialInstructions();
|
||||
instructions = instructions.replace("$api_types", this.apiDocs.getTypeNames().join(", "));
|
||||
return instructions;
|
||||
}
|
||||
|
||||
private registerTools(): void {
|
||||
@ -63,7 +67,7 @@ export class PenpotMcpServer {
|
||||
new PrintTextTool(this),
|
||||
new ExecuteCodeTool(this),
|
||||
new HighLevelOverviewTool(this),
|
||||
new PenpotApiInfoTool(this),
|
||||
new PenpotApiInfoTool(this, this.apiDocs),
|
||||
new ExportShapeTool(this),
|
||||
];
|
||||
|
||||
|
||||
@ -41,9 +41,9 @@ export class PenpotApiInfoTool extends Tool<PenpotApiInfoArgs> {
|
||||
*
|
||||
* @param mcpServer - The MCP server instance
|
||||
*/
|
||||
constructor(mcpServer: PenpotMcpServer) {
|
||||
constructor(mcpServer: PenpotMcpServer, apiDocs: ApiDocs) {
|
||||
super(mcpServer, PenpotApiInfoArgs.schema);
|
||||
this.apiDocs = new ApiDocs();
|
||||
this.apiDocs = apiDocs;
|
||||
}
|
||||
|
||||
public getToolName(): string {
|
||||
@ -51,7 +51,10 @@ export class PenpotApiInfoTool extends Tool<PenpotApiInfoArgs> {
|
||||
}
|
||||
|
||||
public getToolDescription(): string {
|
||||
return "Retrieves Penpot API documentation for types and their members";
|
||||
return (
|
||||
"Retrieves Penpot API documentation for types and their members." +
|
||||
"Be sure to read the 'Penpot High-Level Overview' first."
|
||||
);
|
||||
}
|
||||
|
||||
protected async executeCore(args: PenpotApiInfoArgs): Promise<ToolResponse> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user