Skip to main content
Glama
ProjectController.ts2.22 kB
import { Project } from '../models/Project'; import { ProjectService } from '../services/ProjectService'; export class ProjectController { private projectService: ProjectService; constructor(projectService: ProjectService) { this.projectService = projectService; } async getProjectInfo(projectName: string): Promise<{ content: Array<{ type: "text"; text: string }> }> { try { const project = await this.projectService.getProjectInfo(projectName); if (!project) { return { content: [ { type: "text" as const, text: `未找到名为"${projectName}"的项目。`, }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(project), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `查询项目时出错: ${error instanceof Error ? error.message : '未知错误'}`, }, ], }; } } getProjectCount(): { content: Array<{ type: "text"; text: string }> } { const count = this.projectService.getProjectCount(); return { content: [ { type: 'text', text: `项目总数: ${count}`, }, ], }; } getAllProjects(): { content: Array<{ type: "text"; text: string }> } { const projects = this.projectService.getAllProjects(); return { content: [ { type: 'text', text: JSON.stringify(projects), }, ], }; } async addProject(project: Project): Promise<{ content: Array<{ type: "text"; text: string }> }> { try { await this.projectService.addProject(project); return { content: [ { type: 'text', text: `新增项目成功: ${JSON.stringify(project)}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `新增项目失败: ${error instanceof Error ? error.message : '未知错误'}`, }, ], }; } } }

Implementation Reference

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/sweetwisdom/mcp-demo'

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