-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add result endpoints to MCP tools #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import apiClient from './apiClient' | ||
| import { buildHeaders } from './common' | ||
| import { | ||
| FeatureTotalEvaluationsQuerySchema, | ||
| ProjectTotalEvaluationsQuerySchema, | ||
| } from '../mcp/types' | ||
| import { z } from 'zod' | ||
|
|
||
| export const fetchFeatureTotalEvaluations = async ( | ||
| token: string, | ||
| project_id: string, | ||
| feature_key: string, | ||
| queries: z.infer<typeof FeatureTotalEvaluationsQuerySchema> = {}, | ||
| ) => { | ||
| return apiClient.get( | ||
| '/v1/projects/:project/features/:feature/results/total-evaluations', | ||
| { | ||
| headers: buildHeaders(token), | ||
| params: { | ||
| project: project_id, | ||
| feature: feature_key, | ||
| }, | ||
| queries, | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| export const fetchProjectTotalEvaluations = async ( | ||
| token: string, | ||
| project_id: string, | ||
| queries: z.infer<typeof ProjectTotalEvaluationsQuerySchema> = {}, | ||
| ) => { | ||
| return apiClient.get('/v1/projects/:project/results/total-evaluations', { | ||
| headers: buildHeaders(token), | ||
| params: { | ||
| project: project_id, | ||
| }, | ||
| queries, | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import { Tool } from '@modelcontextprotocol/sdk/types.js' | ||
| import { DevCycleApiClient, handleZodiosValidationErrors } from '../utils/api' | ||
| import { | ||
| fetchFeatureTotalEvaluations, | ||
| fetchProjectTotalEvaluations, | ||
| } from '../../api/results' | ||
| import { | ||
| GetFeatureTotalEvaluationsArgsSchema, | ||
| GetProjectTotalEvaluationsArgsSchema, | ||
| FeatureTotalEvaluationsQuerySchema, | ||
| ProjectTotalEvaluationsQuerySchema, | ||
| } from '../types' | ||
| import { ToolHandler } from '../server' | ||
| import { | ||
| DASHBOARD_LINK_PROPERTY, | ||
| FEATURE_KEY_PROPERTY, | ||
| EVALUATION_QUERY_PROPERTIES, | ||
| EVALUATION_DATA_POINT_SCHEMA, | ||
| PROJECT_DATA_POINT_SCHEMA, | ||
| } from './commonSchemas' | ||
|
|
||
| // Helper functions to generate dashboard links | ||
| const generateFeatureAnalyticsDashboardLink = ( | ||
| orgId: string, | ||
| projectKey: string, | ||
| featureKey: string, | ||
| ): string => { | ||
| return `https://app.devcycle.com/o/${orgId}/p/${projectKey}/features/${featureKey}/analytics` | ||
| } | ||
|
|
||
| const generateProjectAnalyticsDashboardLink = ( | ||
| orgId: string, | ||
| projectKey: string, | ||
| ): string => { | ||
| return `https://app.devcycle.com/o/${orgId}/p/${projectKey}/analytics` | ||
| } | ||
|
|
||
| // ============================================================================= | ||
| // INPUT SCHEMAS | ||
| // ============================================================================= | ||
|
|
||
| const FEATURE_EVALUATION_QUERY_PROPERTIES = { | ||
| featureKey: FEATURE_KEY_PROPERTY, | ||
| ...EVALUATION_QUERY_PROPERTIES, | ||
| } | ||
|
|
||
| const PROJECT_EVALUATION_QUERY_PROPERTIES = EVALUATION_QUERY_PROPERTIES | ||
|
|
||
| // ============================================================================= | ||
| // OUTPUT SCHEMAS | ||
| // ============================================================================= | ||
|
|
||
| const FEATURE_EVALUATIONS_OUTPUT_SCHEMA = { | ||
| type: 'object' as const, | ||
| properties: { | ||
| result: { | ||
| type: 'object' as const, | ||
| description: 'Feature evaluation data aggregated by time period', | ||
| properties: { | ||
| evaluations: { | ||
| type: 'array' as const, | ||
| description: 'Array of evaluation data points', | ||
| items: EVALUATION_DATA_POINT_SCHEMA, | ||
| }, | ||
| cached: { | ||
| type: 'boolean' as const, | ||
| description: 'Whether this result came from cache', | ||
| }, | ||
| updatedAt: { | ||
| type: 'string' as const, | ||
| format: 'date-time' as const, | ||
| description: 'When the data was last updated', | ||
| }, | ||
| }, | ||
| required: ['evaluations', 'cached', 'updatedAt'], | ||
| }, | ||
| dashboardLink: DASHBOARD_LINK_PROPERTY, | ||
| }, | ||
| required: ['result', 'dashboardLink'], | ||
| } | ||
|
|
||
| const PROJECT_EVALUATIONS_OUTPUT_SCHEMA = { | ||
| type: 'object' as const, | ||
| properties: { | ||
| result: { | ||
| type: 'object' as const, | ||
| description: 'Project evaluation data aggregated by time period', | ||
| properties: { | ||
| evaluations: { | ||
| type: 'array' as const, | ||
| description: 'Array of evaluation data points', | ||
| items: PROJECT_DATA_POINT_SCHEMA, | ||
| }, | ||
| cached: { | ||
| type: 'boolean' as const, | ||
| description: 'Whether this result came from cache', | ||
| }, | ||
| updatedAt: { | ||
| type: 'string' as const, | ||
| format: 'date-time' as const, | ||
| description: 'When the data was last updated', | ||
| }, | ||
| }, | ||
| required: ['evaluations', 'cached', 'updatedAt'], | ||
| }, | ||
| dashboardLink: DASHBOARD_LINK_PROPERTY, | ||
| }, | ||
| required: ['result', 'dashboardLink'], | ||
| } | ||
|
|
||
| // ============================================================================= | ||
| // TOOL DEFINITIONS | ||
| // ============================================================================= | ||
|
|
||
| export const resultsToolDefinitions: Tool[] = [ | ||
| { | ||
| name: 'get_feature_total_evaluations', | ||
| description: | ||
| 'Get total variable evaluations per time period for a specific feature. Include dashboard link in the response.', | ||
| inputSchema: { | ||
| type: 'object', | ||
| properties: FEATURE_EVALUATION_QUERY_PROPERTIES, | ||
| required: ['featureKey'], | ||
| }, | ||
| outputSchema: FEATURE_EVALUATIONS_OUTPUT_SCHEMA, | ||
| }, | ||
| { | ||
| name: 'get_project_total_evaluations', | ||
| description: | ||
| 'Get total variable evaluations per time period for the entire project. Include dashboard link in the response.', | ||
| inputSchema: { | ||
| type: 'object', | ||
| properties: PROJECT_EVALUATION_QUERY_PROPERTIES, | ||
| }, | ||
| outputSchema: PROJECT_EVALUATIONS_OUTPUT_SCHEMA, | ||
| }, | ||
| ] | ||
|
|
||
| export const resultsToolHandlers: Record<string, ToolHandler> = { | ||
| get_feature_total_evaluations: async ( | ||
| args: unknown, | ||
| apiClient: DevCycleApiClient, | ||
| ) => { | ||
| const validatedArgs = GetFeatureTotalEvaluationsArgsSchema.parse(args) | ||
|
|
||
| return await apiClient.executeWithDashboardLink( | ||
| 'getFeatureTotalEvaluations', | ||
| validatedArgs, | ||
| async (authToken, projectKey) => { | ||
| const { featureKey, ...apiQueries } = validatedArgs | ||
|
|
||
| return await handleZodiosValidationErrors( | ||
| () => | ||
| fetchFeatureTotalEvaluations( | ||
| authToken, | ||
| projectKey, | ||
| featureKey, | ||
| apiQueries, | ||
| ), | ||
| 'fetchFeatureTotalEvaluations', | ||
| ) | ||
| }, | ||
| (orgId, projectKey) => | ||
| generateFeatureAnalyticsDashboardLink( | ||
| orgId, | ||
| projectKey, | ||
| validatedArgs.featureKey, | ||
| ), | ||
| ) | ||
| }, | ||
| get_project_total_evaluations: async ( | ||
| args: unknown, | ||
| apiClient: DevCycleApiClient, | ||
| ) => { | ||
| const validatedArgs = GetProjectTotalEvaluationsArgsSchema.parse(args) | ||
|
|
||
| return await apiClient.executeWithDashboardLink( | ||
| 'getProjectTotalEvaluations', | ||
| validatedArgs, | ||
| async (authToken, projectKey) => { | ||
| return await handleZodiosValidationErrors( | ||
| () => | ||
| fetchProjectTotalEvaluations( | ||
| authToken, | ||
| projectKey, | ||
| validatedArgs, | ||
| ), | ||
| 'fetchProjectTotalEvaluations', | ||
| ) | ||
| }, | ||
| generateProjectAnalyticsDashboardLink, | ||
| ) | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should rate limit this endpoint - or start caching the results from snowflake. If MCP servers are calling this with any frequency they'll get rate-limited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea we can keep an eye on that through DD, and add a rate limit if needed to the API