get_projects
Retrieve accessible Jira projects by providing user email and resource ID to manage project visibility and permissions.
Instructions
Get the projects the user has access to
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userEmail | Yes | The email of the user accessing the projects. | |
| resourceId | Yes | The id of the resource being used to call to get the projects. |
Implementation Reference
- src/tools/getProjects.ts:8-67 (handler)The main handler function that implements the 'get_projects' tool. It retrieves cached user data, creates an API instance for Jira, calls the project search endpoint, and returns the list of projects with id, key, and name fields.
export function getProjectsTool(server: McpServer) { server.tool( 'get_projects', 'Get the projects the user has access to', { userEmail: z.string().email().describe("The email of the user accessing the projects."), resourceId: z.string().describe("The id of the resource being used to call to get the projects."), }, async ({userEmail, resourceId}) => { const cacheData = await getUpdatedCachedData(userEmail); if(!cacheData) { return { isError: true, content: [ { type: "text", text: `Please try again after user confirmed that he authorized the app to access the Jira data.`, }, ], }; } const api = getApiInstance(`https://api.atlassian.com/ex/jira/${resourceId}`, cacheData.accessToken); const response = await api.get('/rest/api/3/project/search'); if (response.status !== Constants.OK) { logger.error('Error fetching projects:', response.statusText, response.data, userEmail); return { isError: true, content: [ { type: "text", text: `Error getting projects: ${response.statusText}`, }, ], }; } const data = response.data.values.map((val: any) => ({ id: val.id, key: val.key, name: val.name, })) logger.info('Fetched projects:', data); return { content: [ { type: "text", text: JSON.stringify(data), }, ], }; } ); } - src/tools/getProjects.ts:12-15 (schema)Zod schema defining the input parameters for the get_projects tool: userEmail (required, must be valid email format) and resourceId (required string).
{ userEmail: z.string().email().describe("The email of the user accessing the projects."), resourceId: z.string().describe("The id of the resource being used to call to get the projects."), }, - src/tools/index.ts:6-10 (registration)Registration function that calls getProjectsTool(server) to register the 'get_projects' tool with the MCP server instance.
export function registerTools(server: McpServer) { createIssueTool(server); getProjectsTool(server); getAccessibleResourcesTool(server); }