getCurrentProject
Retrieves the current Teamwork project by checking the .teamwork file or prompting the user for the project ID.
Instructions
Get the current solution's Teamwork project, always check the .teamwork file in the root of the solution for the Teamwork project ID or ask the user which project they are working on.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | The current Teamwork project ID associated with the solution. |
Implementation Reference
- The tool handler that receives input, extracts projectId, calls the service, and returns the result as MCP content.
export async function handleGetCurrentProject(input: any) { try { const projectId = String(input?.projectId); if (!projectId) { throw new Error("Project ID is required"); } const result = await teamworkService.getCurrentProject(projectId); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error: any) { return createErrorResponse(error, 'Retrieving current project'); } } - The tool definition/schema including name, description, inputSchema (requires projectId as integer), and annotations.
export const getCurrentProjectDefinition = { name: "getCurrentProject", description: "Get the current solution's Teamwork project, always check the `.teamwork` file in the root of the solution for the Teamwork project ID or ask the user which project they are working on.", inputSchema: { type: "object", properties: { projectId: { type: "integer", description: "The current Teamwork project ID associated with the solution." } }, required: ["projectId"] }, annotations: { title: "Get the Current Project", readOnlyHint: false, destructiveHint: false, openWorldHint: false } }; - The service-layer implementation that calls the Teamwork API at /projects/{projectId}.json to fetch the current project.
import logger from '../../utils/logger.js'; import { ensureApiClient } from '../core/apiClient.js'; /** * Gets the current Teamwork project * @param projectId The Teamwork project ID that you should first find stored in the .teamwork file in the solution root * @returns An object with success status and project details or error message */ export const getCurrentProject = async (projectId: string) => { try { if (!projectId) { return { success: false, error: `Current Teamwork project ID was not provided` }; } const api = ensureApiClient(); const response = await api.get(`/projects/${projectId}.json`); return response.data; } catch (error: any) { logger.error(`Error getting current project: ${error.message}`); throw new Error(`Failed to get current project`); }; }; export default getCurrentProject; - src/tools/index.ts:8-8 (registration)Import of the tool definition and handler from the getCurrentProject module.
import { getCurrentProjectDefinition as getCurrentProject, handleGetCurrentProject } from './projects/getCurrentProject.js'; - src/tools/index.ts:67-67 (registration)Registration of the getCurrentProject tool in the toolPairs array with its definition and handler.
{ definition: getCurrentProject, handler: handleGetCurrentProject },