@langwatch/server 3.1.0-beta.4 → 3.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
- package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
- package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
- package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
- package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
- package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
- package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
- package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
- package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
- package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
- package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
- package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
- package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
- package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
- package/langwatch/ee/admin/impersonation.service.ts +170 -0
- package/langwatch/ee/admin/isAdmin.ts +9 -0
- package/langwatch/ee/admin/routes/admin.ts +531 -0
- package/langwatch/ee/admin/safeSelects.ts +64 -0
- package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
- package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
- package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
- package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
- package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
- package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
- package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
- package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
- package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
- package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
- package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
- package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
- package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
- package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
- package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
- package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
- package/langwatch/ee/billing/currencyRouter.ts +18 -0
- package/langwatch/ee/billing/errors.ts +129 -0
- package/langwatch/ee/billing/index.ts +67 -0
- package/langwatch/ee/billing/middleware.ts +17 -0
- package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
- package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
- package/langwatch/ee/billing/notifications/types.ts +9 -0
- package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
- package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
- package/langwatch/ee/billing/nurturing/types.ts +125 -0
- package/langwatch/ee/billing/planLimits.ts +190 -0
- package/langwatch/ee/billing/planProvider.ts +119 -0
- package/langwatch/ee/billing/planTypes.ts +53 -0
- package/langwatch/ee/billing/pricing.ts +57 -0
- package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
- package/langwatch/ee/billing/services/customerService.ts +90 -0
- package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
- package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
- package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
- package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
- package/langwatch/ee/billing/services/subscription.service.ts +549 -0
- package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
- package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
- package/langwatch/ee/billing/services/webhookService.ts +858 -0
- package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
- package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
- package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
- package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
- package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
- package/langwatch/ee/billing/types.ts +102 -0
- package/langwatch/ee/billing/utils/currency.ts +99 -0
- package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
- package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
- package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
- package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
- package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
- package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
- package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
- package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
- package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
- package/langwatch/ee/licensing/client.ts +29 -0
- package/langwatch/ee/licensing/constants.ts +195 -0
- package/langwatch/ee/licensing/defaults.ts +55 -0
- package/langwatch/ee/licensing/errors.ts +11 -0
- package/langwatch/ee/licensing/index.ts +52 -0
- package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
- package/langwatch/ee/licensing/licenseHandler.ts +308 -0
- package/langwatch/ee/licensing/planInfo.ts +46 -0
- package/langwatch/ee/licensing/planMapping.ts +37 -0
- package/langwatch/ee/licensing/planTemplates.ts +109 -0
- package/langwatch/ee/licensing/server.ts +43 -0
- package/langwatch/ee/licensing/signing.ts +43 -0
- package/langwatch/ee/licensing/types.ts +156 -0
- package/langwatch/ee/licensing/validation.ts +107 -0
- package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
- package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
- package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
- package/langwatch/package.json +1 -1
- package/langwatch/pnpm-workspace.yaml +0 -1
- package/mcp-server/.env.example +2 -0
- package/mcp-server/.eslintrc.cjs +36 -0
- package/mcp-server/CHANGELOG.md +165 -0
- package/mcp-server/CONTRIBUTING.md +96 -0
- package/mcp-server/README.md +172 -0
- package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
- package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
- package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
- package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
- package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
- package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
- package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
- package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
- package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
- package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
- package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
- package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
- package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
- package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
- package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
- package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
- package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
- package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
- package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
- package/mcp-server/dist/config.d.ts +17 -0
- package/mcp-server/dist/config.js +13 -0
- package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
- package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
- package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
- package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
- package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
- package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
- package/mcp-server/dist/create-mcp-server.d.ts +8 -0
- package/mcp-server/dist/create-mcp-server.js +8 -0
- package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
- package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
- package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
- package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
- package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
- package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
- package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
- package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
- package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
- package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
- package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
- package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
- package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
- package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
- package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
- package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
- package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
- package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
- package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
- package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
- package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
- package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
- package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
- package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
- package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
- package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
- package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
- package/mcp-server/dist/index.d.ts +2 -0
- package/mcp-server/dist/index.js +67774 -0
- package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
- package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
- package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
- package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
- package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
- package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
- package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
- package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
- package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
- package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
- package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
- package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
- package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
- package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
- package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
- package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
- package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
- package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
- package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
- package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
- package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
- package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
- package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
- package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
- package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
- package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
- package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
- package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
- package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
- package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
- package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
- package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
- package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
- package/mcp-server/package.json +79 -0
- package/mcp-server/pnpm-lock.yaml +6103 -0
- package/mcp-server/pnpm-workspace.yaml +2 -0
- package/mcp-server/pyproject.toml +17 -0
- package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
- package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
- package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
- package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
- package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
- package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
- package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
- package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
- package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
- package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
- package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
- package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
- package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
- package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
- package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
- package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
- package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
- package/mcp-server/src/config.d.ts +15 -0
- package/mcp-server/src/config.ts +107 -0
- package/mcp-server/src/create-mcp-server.d.ts +6 -0
- package/mcp-server/src/create-mcp-server.ts +1799 -0
- package/mcp-server/src/http-server.ts +329 -0
- package/mcp-server/src/index.ts +46 -0
- package/mcp-server/src/langwatch-api-agents.ts +108 -0
- package/mcp-server/src/langwatch-api-annotations.ts +49 -0
- package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
- package/mcp-server/src/langwatch-api-datasets.ts +191 -0
- package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
- package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
- package/mcp-server/src/langwatch-api-monitors.ts +82 -0
- package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
- package/mcp-server/src/langwatch-api-secrets.ts +48 -0
- package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
- package/mcp-server/src/langwatch-api-suites.ts +118 -0
- package/mcp-server/src/langwatch-api-triggers.ts +48 -0
- package/mcp-server/src/langwatch-api-workflows.ts +41 -0
- package/mcp-server/src/langwatch-api.ts +299 -0
- package/mcp-server/src/schemas/analytics-groups.ts +78 -0
- package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
- package/mcp-server/src/schemas/create-dataset.ts +48 -0
- package/mcp-server/src/schemas/filter-fields.ts +119 -0
- package/mcp-server/src/schemas/index.ts +4 -0
- package/mcp-server/src/tools/archive-scenario.ts +19 -0
- package/mcp-server/src/tools/archive-suite.ts +12 -0
- package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
- package/mcp-server/src/tools/create-agent.ts +15 -0
- package/mcp-server/src/tools/create-annotation.ts +18 -0
- package/mcp-server/src/tools/create-dashboard.ts +7 -0
- package/mcp-server/src/tools/create-dataset-records.ts +23 -0
- package/mcp-server/src/tools/create-dataset.ts +22 -0
- package/mcp-server/src/tools/create-evaluator.ts +33 -0
- package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/create-prompt.ts +58 -0
- package/mcp-server/src/tools/create-scenario.ts +30 -0
- package/mcp-server/src/tools/create-suite.ts +42 -0
- package/mcp-server/src/tools/delete-agent.ts +7 -0
- package/mcp-server/src/tools/delete-annotation.ts +7 -0
- package/mcp-server/src/tools/delete-dashboard.ts +7 -0
- package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
- package/mcp-server/src/tools/delete-dataset.ts +20 -0
- package/mcp-server/src/tools/delete-evaluator.ts +12 -0
- package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/delete-workflow.ts +7 -0
- package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
- package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
- package/mcp-server/src/tools/discover-schema.ts +106 -0
- package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
- package/mcp-server/src/tools/get-agent.ts +21 -0
- package/mcp-server/src/tools/get-analytics.ts +98 -0
- package/mcp-server/src/tools/get-dashboard.ts +22 -0
- package/mcp-server/src/tools/get-dataset.ts +63 -0
- package/mcp-server/src/tools/get-evaluator.ts +53 -0
- package/mcp-server/src/tools/get-prompt.ts +54 -0
- package/mcp-server/src/tools/get-scenario.ts +36 -0
- package/mcp-server/src/tools/get-simulation-run.ts +60 -0
- package/mcp-server/src/tools/get-suite.ts +47 -0
- package/mcp-server/src/tools/get-trace.ts +61 -0
- package/mcp-server/src/tools/get-workflow.ts +17 -0
- package/mcp-server/src/tools/list-agents.ts +27 -0
- package/mcp-server/src/tools/list-annotations.ts +33 -0
- package/mcp-server/src/tools/list-dashboards.ts +27 -0
- package/mcp-server/src/tools/list-dataset-records.ts +46 -0
- package/mcp-server/src/tools/list-datasets.ts +80 -0
- package/mcp-server/src/tools/list-evaluators.ts +37 -0
- package/mcp-server/src/tools/list-model-providers.ts +40 -0
- package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
- package/mcp-server/src/tools/list-prompts.ts +34 -0
- package/mcp-server/src/tools/list-scenarios.ts +47 -0
- package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
- package/mcp-server/src/tools/list-suites.ts +43 -0
- package/mcp-server/src/tools/list-workflows.ts +31 -0
- package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
- package/mcp-server/src/tools/run-agent.ts +36 -0
- package/mcp-server/src/tools/run-evaluation.ts +87 -0
- package/mcp-server/src/tools/run-suite.ts +28 -0
- package/mcp-server/src/tools/run-workflow.ts +36 -0
- package/mcp-server/src/tools/search-traces.ts +91 -0
- package/mcp-server/src/tools/set-model-provider.ts +46 -0
- package/mcp-server/src/tools/update-agent.ts +13 -0
- package/mcp-server/src/tools/update-dataset-record.ts +21 -0
- package/mcp-server/src/tools/update-dataset.ts +23 -0
- package/mcp-server/src/tools/update-evaluator.ts +30 -0
- package/mcp-server/src/tools/update-prompt.ts +31 -0
- package/mcp-server/src/tools/update-scenario.ts +32 -0
- package/mcp-server/src/tools/update-suite.ts +44 -0
- package/mcp-server/src/utils/date-parsing.ts +31 -0
- package/mcp-server/src/utils/escape-markdown.ts +12 -0
- package/mcp-server/tsconfig.json +27 -0
- package/mcp-server/uv.lock +2731 -0
- package/package.json +2 -1
- package/packages/server/dist/cli.cjs +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEvaluator,
|
|
3
|
+
getEvaluatorType
|
|
4
|
+
} from "./chunk-HYMIWO3U.js";
|
|
5
|
+
import "./chunk-2WPLXEKF.js";
|
|
6
|
+
import "./chunk-BWWY5KEF.js";
|
|
7
|
+
|
|
8
|
+
// src/tools/get-evaluator.ts
|
|
9
|
+
async function handleGetEvaluator(params) {
|
|
10
|
+
const evaluator = await getEvaluator(params.idOrSlug);
|
|
11
|
+
const evaluatorType = getEvaluatorType(evaluator);
|
|
12
|
+
const lines = [];
|
|
13
|
+
lines.push(`# Evaluator: ${evaluator.name}
|
|
14
|
+
`);
|
|
15
|
+
lines.push(`**ID**: ${evaluator.id}`);
|
|
16
|
+
if (evaluator.slug) lines.push(`**Slug**: ${evaluator.slug}`);
|
|
17
|
+
lines.push(`**Kind**: ${evaluator.type}`);
|
|
18
|
+
if (evaluatorType) lines.push(`**Evaluator Type**: ${evaluatorType}`);
|
|
19
|
+
if (evaluator.config) {
|
|
20
|
+
lines.push("\n## Config");
|
|
21
|
+
lines.push("```json");
|
|
22
|
+
lines.push(JSON.stringify(evaluator.config, null, 2));
|
|
23
|
+
lines.push("```");
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(evaluator.fields) && evaluator.fields.length > 0) {
|
|
26
|
+
lines.push("\n## Input Fields");
|
|
27
|
+
for (const field of evaluator.fields) {
|
|
28
|
+
const opt = field.optional ? " (optional)" : "";
|
|
29
|
+
lines.push(`- **${field.identifier}** (${field.type})${opt}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(evaluator.outputFields) && evaluator.outputFields.length > 0) {
|
|
33
|
+
lines.push("\n## Output Fields");
|
|
34
|
+
for (const field of evaluator.outputFields) {
|
|
35
|
+
lines.push(`- **${field.identifier}** (${field.type})`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (evaluator.workflowName) {
|
|
39
|
+
lines.push(`
|
|
40
|
+
**Workflow**: ${evaluator.workflowName}`);
|
|
41
|
+
}
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
handleGetEvaluator
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=get-evaluator-UWVUPYTM.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getPrompt
|
|
3
|
+
} from "./chunk-2WPLXEKF.js";
|
|
4
|
+
import "./chunk-BWWY5KEF.js";
|
|
5
|
+
|
|
6
|
+
// src/tools/get-prompt.ts
|
|
7
|
+
async function handleGetPrompt(params) {
|
|
8
|
+
const prompt = await getPrompt(params.idOrHandle, { version: params.version, tag: params.tag });
|
|
9
|
+
const lines = [];
|
|
10
|
+
lines.push(
|
|
11
|
+
`# Prompt: ${prompt.name || prompt.handle || prompt.id}
|
|
12
|
+
`
|
|
13
|
+
);
|
|
14
|
+
if (prompt.handle) lines.push(`**Handle**: ${prompt.handle}`);
|
|
15
|
+
if (prompt.id) lines.push(`**ID**: ${prompt.id}`);
|
|
16
|
+
if (prompt.latestVersionNumber != null)
|
|
17
|
+
lines.push(`**Latest Version**: v${prompt.latestVersionNumber}`);
|
|
18
|
+
const version = prompt.versions?.[0] ?? prompt;
|
|
19
|
+
if (version.model) lines.push(`**Model**: ${version.model}`);
|
|
20
|
+
const messages = version.messages || prompt.prompt || [];
|
|
21
|
+
if (Array.isArray(messages) && messages.length > 0) {
|
|
22
|
+
lines.push("\n## Messages");
|
|
23
|
+
for (const msg of messages) {
|
|
24
|
+
lines.push(`
|
|
25
|
+
### ${msg.role}`);
|
|
26
|
+
lines.push(msg.content);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (prompt.versions && prompt.versions.length > 0) {
|
|
30
|
+
lines.push("\n## Version History");
|
|
31
|
+
for (const v of prompt.versions.slice(0, 10)) {
|
|
32
|
+
const versionNum = v.version ?? "?";
|
|
33
|
+
const commitMsg = v.commitMessage || "No message";
|
|
34
|
+
lines.push(`- **v${versionNum}**: ${commitMsg}`);
|
|
35
|
+
}
|
|
36
|
+
if (prompt.versions.length > 10) {
|
|
37
|
+
lines.push(`... and ${prompt.versions.length - 10} more versions`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
handleGetPrompt
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=get-prompt-WZUOLLQC.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getScenario
|
|
3
|
+
} from "./chunk-2GT7IFWK.js";
|
|
4
|
+
import "./chunk-2WPLXEKF.js";
|
|
5
|
+
import "./chunk-BWWY5KEF.js";
|
|
6
|
+
|
|
7
|
+
// src/tools/get-scenario.ts
|
|
8
|
+
async function handleGetScenario(params) {
|
|
9
|
+
const scenario = await getScenario(params.scenarioId);
|
|
10
|
+
if (params.format === "json") {
|
|
11
|
+
return JSON.stringify(scenario, null, 2);
|
|
12
|
+
}
|
|
13
|
+
const lines = [];
|
|
14
|
+
lines.push(`# Scenario: ${scenario.name}
|
|
15
|
+
`);
|
|
16
|
+
lines.push(`**ID**: ${scenario.id}`);
|
|
17
|
+
lines.push(`**Situation**: ${scenario.situation}`);
|
|
18
|
+
if (Array.isArray(scenario.criteria) && scenario.criteria.length > 0) {
|
|
19
|
+
lines.push("\n## Criteria");
|
|
20
|
+
for (const criterion of scenario.criteria) {
|
|
21
|
+
lines.push(`- ${criterion}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(scenario.labels) && scenario.labels.length > 0) {
|
|
25
|
+
lines.push(`
|
|
26
|
+
**Labels**: ${scenario.labels.join(", ")}`);
|
|
27
|
+
}
|
|
28
|
+
return lines.join("\n");
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
handleGetScenario
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=get-scenario-Q6LCNUYN.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSimulationRun
|
|
3
|
+
} from "./chunk-EGH5RPXM.js";
|
|
4
|
+
import "./chunk-2WPLXEKF.js";
|
|
5
|
+
import "./chunk-BWWY5KEF.js";
|
|
6
|
+
|
|
7
|
+
// src/tools/get-simulation-run.ts
|
|
8
|
+
async function handleGetSimulationRun(params) {
|
|
9
|
+
const run = await getSimulationRun(params.scenarioRunId);
|
|
10
|
+
if (params.format === "json") {
|
|
11
|
+
return JSON.stringify(run, null, 2);
|
|
12
|
+
}
|
|
13
|
+
const lines = [];
|
|
14
|
+
lines.push(`# Simulation Run: ${run.name ?? run.scenarioRunId}
|
|
15
|
+
`);
|
|
16
|
+
lines.push(`**Run ID**: ${run.scenarioRunId}`);
|
|
17
|
+
lines.push(`**Scenario ID**: ${run.scenarioId}`);
|
|
18
|
+
lines.push(`**Batch ID**: ${run.batchRunId}`);
|
|
19
|
+
lines.push(`**Status**: ${run.status}`);
|
|
20
|
+
const duration = run.durationInMs > 0 ? `${(run.durationInMs / 1e3).toFixed(1)}s` : "\u2014";
|
|
21
|
+
lines.push(`**Duration**: ${duration}`);
|
|
22
|
+
if (run.totalCost) {
|
|
23
|
+
lines.push(`**Cost**: $${run.totalCost.toFixed(4)}`);
|
|
24
|
+
}
|
|
25
|
+
lines.push(`**Started**: ${new Date(run.timestamp).toISOString()}`);
|
|
26
|
+
if (run.results) {
|
|
27
|
+
lines.push("\n## Results");
|
|
28
|
+
if (run.results.verdict) {
|
|
29
|
+
lines.push(`**Verdict**: ${run.results.verdict}`);
|
|
30
|
+
}
|
|
31
|
+
if (run.results.reasoning) {
|
|
32
|
+
lines.push(`**Reasoning**: ${run.results.reasoning}`);
|
|
33
|
+
}
|
|
34
|
+
if (run.results.metCriteria && run.results.metCriteria.length > 0) {
|
|
35
|
+
lines.push(`**Met Criteria**: ${run.results.metCriteria.join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
if (run.results.unmetCriteria && run.results.unmetCriteria.length > 0) {
|
|
38
|
+
lines.push(`**Unmet Criteria**: ${run.results.unmetCriteria.join(", ")}`);
|
|
39
|
+
}
|
|
40
|
+
if (run.results.error) {
|
|
41
|
+
lines.push(`**Error**: ${run.results.error}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (run.messages && run.messages.length > 0) {
|
|
45
|
+
lines.push("\n## Conversation");
|
|
46
|
+
for (const msg of run.messages) {
|
|
47
|
+
const content = msg.content.length > 300 ? msg.content.slice(0, 300) + "..." : msg.content;
|
|
48
|
+
lines.push(`**[${msg.role}]**: ${content}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return lines.join("\n");
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
handleGetSimulationRun
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=get-simulation-run-Z2XKO256.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSuite
|
|
3
|
+
} from "./chunk-LUMEZEHL.js";
|
|
4
|
+
import "./chunk-2WPLXEKF.js";
|
|
5
|
+
import "./chunk-BWWY5KEF.js";
|
|
6
|
+
|
|
7
|
+
// src/tools/get-suite.ts
|
|
8
|
+
async function handleGetSuite(params) {
|
|
9
|
+
const suite = await getSuite(params.id);
|
|
10
|
+
if (params.format === "json") {
|
|
11
|
+
return JSON.stringify(suite, null, 2);
|
|
12
|
+
}
|
|
13
|
+
const lines = [];
|
|
14
|
+
lines.push(`# Suite: ${suite.name}
|
|
15
|
+
`);
|
|
16
|
+
lines.push(`**ID**: ${suite.id}`);
|
|
17
|
+
lines.push(`**Slug**: ${suite.slug}`);
|
|
18
|
+
lines.push(`**Description**: ${suite.description ?? "\u2014"}`);
|
|
19
|
+
lines.push(`**Repeat Count**: ${suite.repeatCount}`);
|
|
20
|
+
lines.push(`**Created**: ${suite.createdAt}`);
|
|
21
|
+
lines.push(`**Updated**: ${suite.updatedAt}`);
|
|
22
|
+
if (suite.labels.length > 0) {
|
|
23
|
+
lines.push(`**Labels**: ${suite.labels.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
lines.push("\n## Scenarios");
|
|
26
|
+
for (const id of suite.scenarioIds) {
|
|
27
|
+
lines.push(`- ${id}`);
|
|
28
|
+
}
|
|
29
|
+
lines.push("\n## Targets");
|
|
30
|
+
for (const t of suite.targets) {
|
|
31
|
+
lines.push(`- ${t.type}:${t.referenceId}`);
|
|
32
|
+
}
|
|
33
|
+
const totalJobs = suite.scenarioIds.length * suite.targets.length * suite.repeatCount;
|
|
34
|
+
lines.push(`
|
|
35
|
+
**Total jobs per run**: ${totalJobs}`);
|
|
36
|
+
lines.push(
|
|
37
|
+
"\n> Use `platform_run_suite` to trigger a run, or `platform_update_suite` to modify."
|
|
38
|
+
);
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
handleGetSuite
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=get-suite-BXK5TN7P.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTraceById
|
|
3
|
+
} from "./chunk-2WPLXEKF.js";
|
|
4
|
+
import "./chunk-BWWY5KEF.js";
|
|
5
|
+
|
|
6
|
+
// src/tools/get-trace.ts
|
|
7
|
+
async function handleGetTrace(params) {
|
|
8
|
+
const format = params.format ?? "digest";
|
|
9
|
+
const result = await getTraceById(params.traceId, format);
|
|
10
|
+
if (format === "json") {
|
|
11
|
+
return JSON.stringify(result, null, 2);
|
|
12
|
+
}
|
|
13
|
+
const lines = [];
|
|
14
|
+
lines.push(`# Trace: ${params.traceId}
|
|
15
|
+
`);
|
|
16
|
+
if (result.timestamps) {
|
|
17
|
+
lines.push(`**Started**: ${result.timestamps.started_at}`);
|
|
18
|
+
if (result.timestamps.updated_at)
|
|
19
|
+
lines.push(`**Updated**: ${result.timestamps.updated_at}`);
|
|
20
|
+
}
|
|
21
|
+
if (result.metadata) {
|
|
22
|
+
const meta = result.metadata;
|
|
23
|
+
if (meta.user_id) lines.push(`**User**: ${meta.user_id}`);
|
|
24
|
+
if (meta.thread_id) lines.push(`**Thread**: ${meta.thread_id}`);
|
|
25
|
+
if (meta.customer_id) lines.push(`**Customer**: ${meta.customer_id}`);
|
|
26
|
+
if (meta.labels?.length) lines.push(`**Labels**: ${meta.labels.join(", ")}`);
|
|
27
|
+
}
|
|
28
|
+
if (result.evaluations && result.evaluations.length > 0) {
|
|
29
|
+
lines.push("\n## Evaluations");
|
|
30
|
+
for (const evaluation of result.evaluations) {
|
|
31
|
+
const status = evaluation.passed === true ? "PASSED" : evaluation.passed === false ? "FAILED" : "N/A";
|
|
32
|
+
lines.push(
|
|
33
|
+
`- **${evaluation.name || evaluation.evaluator_id}**: ${status}${evaluation.score != null ? ` (score: ${evaluation.score})` : ""}${evaluation.label ? ` [${evaluation.label}]` : ""}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (result.formatted_trace) {
|
|
38
|
+
lines.push(`
|
|
39
|
+
## Trace Details
|
|
40
|
+
${result.formatted_trace}`);
|
|
41
|
+
}
|
|
42
|
+
lines.push(
|
|
43
|
+
'\n> Tip: Use `get_trace` with `format: "json"` to get the full raw trace data.'
|
|
44
|
+
);
|
|
45
|
+
return lines.join("\n");
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
handleGetTrace
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=get-trace-4EJAYVBG.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getWorkflow
|
|
3
|
+
} from "./chunk-ZVS4UKN2.js";
|
|
4
|
+
import "./chunk-2WPLXEKF.js";
|
|
5
|
+
import "./chunk-BWWY5KEF.js";
|
|
6
|
+
|
|
7
|
+
// src/tools/get-workflow.ts
|
|
8
|
+
async function handleGetWorkflow(params) {
|
|
9
|
+
const workflow = await getWorkflow(params.id);
|
|
10
|
+
const lines = [];
|
|
11
|
+
lines.push(`# ${workflow.name}
|
|
12
|
+
`);
|
|
13
|
+
lines.push(`**ID**: ${workflow.id}`);
|
|
14
|
+
if (workflow.description) lines.push(`**Description**: ${workflow.description}`);
|
|
15
|
+
if (workflow.icon) lines.push(`**Icon**: ${workflow.icon}`);
|
|
16
|
+
lines.push(`**Evaluator**: ${workflow.isEvaluator ? "yes" : "no"}`);
|
|
17
|
+
lines.push(`**Component**: ${workflow.isComponent ? "yes" : "no"}`);
|
|
18
|
+
lines.push(`**Created**: ${workflow.createdAt}`);
|
|
19
|
+
lines.push(`**Updated**: ${workflow.updatedAt}`);
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
handleGetWorkflow
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=get-workflow-O34QJLHD.js.map
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMcpServer
|
|
3
|
+
} from "./chunk-UDHJYT6P.js";
|
|
4
|
+
import {
|
|
5
|
+
getConfig,
|
|
6
|
+
runWithConfig
|
|
7
|
+
} from "./chunk-BWWY5KEF.js";
|
|
8
|
+
|
|
9
|
+
// src/http-server.ts
|
|
10
|
+
import express from "express";
|
|
11
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
12
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
13
|
+
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
14
|
+
import { randomUUID, createHash } from "crypto";
|
|
15
|
+
var oauthTokens = /* @__PURE__ */ new Map();
|
|
16
|
+
function extractBearerToken(req) {
|
|
17
|
+
const authHeader = req.headers.authorization;
|
|
18
|
+
if (!authHeader?.startsWith("Bearer ")) return null;
|
|
19
|
+
const token = authHeader.slice(7) || null;
|
|
20
|
+
if (!token) return null;
|
|
21
|
+
const oauthEntry = oauthTokens.get(token);
|
|
22
|
+
if (oauthEntry) {
|
|
23
|
+
if (Date.now() < oauthEntry.expiresAt) {
|
|
24
|
+
return oauthEntry.apiKey;
|
|
25
|
+
}
|
|
26
|
+
oauthTokens.delete(token);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return token;
|
|
30
|
+
}
|
|
31
|
+
function generateAccessToken() {
|
|
32
|
+
return createHash("sha256").update(randomUUID()).digest("hex");
|
|
33
|
+
}
|
|
34
|
+
async function handleWithSessionConfig(apiKey, fn) {
|
|
35
|
+
const baseConfig = getConfig();
|
|
36
|
+
return runWithConfig({ ...baseConfig, apiKey }, fn);
|
|
37
|
+
}
|
|
38
|
+
async function startHttpServer({
|
|
39
|
+
port
|
|
40
|
+
}) {
|
|
41
|
+
const app = express();
|
|
42
|
+
app.set("trust proxy", true);
|
|
43
|
+
app.use(express.json());
|
|
44
|
+
app.use((_req, res, next) => {
|
|
45
|
+
res.header("Access-Control-Allow-Origin", "*");
|
|
46
|
+
res.header(
|
|
47
|
+
"Access-Control-Allow-Methods",
|
|
48
|
+
"GET, POST, DELETE, OPTIONS"
|
|
49
|
+
);
|
|
50
|
+
res.header(
|
|
51
|
+
"Access-Control-Allow-Headers",
|
|
52
|
+
"Content-Type, Authorization, mcp-session-id, MCP-Protocol-Version"
|
|
53
|
+
);
|
|
54
|
+
if (_req.method === "OPTIONS") {
|
|
55
|
+
res.sendStatus(200);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
next();
|
|
59
|
+
});
|
|
60
|
+
app.get("/health", (_req, res) => {
|
|
61
|
+
res.json({ status: "ok" });
|
|
62
|
+
});
|
|
63
|
+
app.get(
|
|
64
|
+
"/.well-known/oauth-authorization-server",
|
|
65
|
+
(_req, res) => {
|
|
66
|
+
const baseUrl = `${_req.protocol}://${_req.get("host")}`;
|
|
67
|
+
res.json({
|
|
68
|
+
issuer: baseUrl,
|
|
69
|
+
token_endpoint: `${baseUrl}/oauth/token`,
|
|
70
|
+
token_endpoint_auth_methods_supported: ["client_secret_post"],
|
|
71
|
+
grant_types_supported: ["client_credentials"],
|
|
72
|
+
response_types_supported: [],
|
|
73
|
+
scopes_supported: ["mcp:tools"]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
app.post(
|
|
78
|
+
"/oauth/token",
|
|
79
|
+
express.urlencoded({ extended: false }),
|
|
80
|
+
(req, res) => {
|
|
81
|
+
const grantType = req.body.grant_type;
|
|
82
|
+
if (grantType !== "client_credentials") {
|
|
83
|
+
res.status(400).json({
|
|
84
|
+
error: "unsupported_grant_type",
|
|
85
|
+
error_description: "Only client_credentials grant type is supported"
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const clientSecret = req.body.client_secret;
|
|
90
|
+
if (!clientSecret || typeof clientSecret !== "string") {
|
|
91
|
+
res.status(400).json({
|
|
92
|
+
error: "invalid_request",
|
|
93
|
+
error_description: "client_secret is required (use your LangWatch API key)"
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const expiresIn = 3600;
|
|
98
|
+
const accessToken = generateAccessToken();
|
|
99
|
+
oauthTokens.set(accessToken, {
|
|
100
|
+
apiKey: clientSecret,
|
|
101
|
+
expiresAt: Date.now() + expiresIn * 1e3
|
|
102
|
+
});
|
|
103
|
+
res.json({
|
|
104
|
+
access_token: accessToken,
|
|
105
|
+
token_type: "Bearer",
|
|
106
|
+
expires_in: expiresIn,
|
|
107
|
+
scope: "mcp:tools"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
const sessions = {};
|
|
112
|
+
app.post("/mcp", async (req, res) => {
|
|
113
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
114
|
+
if (sessionId && sessions[sessionId]) {
|
|
115
|
+
const session = sessions[sessionId];
|
|
116
|
+
await handleWithSessionConfig(
|
|
117
|
+
session.apiKey,
|
|
118
|
+
() => session.transport.handleRequest(req, res, req.body)
|
|
119
|
+
);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!sessionId && isInitializeRequest(req.body)) {
|
|
123
|
+
const apiKey = extractBearerToken(req);
|
|
124
|
+
if (!apiKey) {
|
|
125
|
+
res.status(401).json({
|
|
126
|
+
error: "Authorization: Bearer <LANGWATCH_API_KEY> header required"
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const transport = new StreamableHTTPServerTransport({
|
|
131
|
+
sessionIdGenerator: () => randomUUID(),
|
|
132
|
+
onsessioninitialized: (id) => {
|
|
133
|
+
sessions[id] = { transport, apiKey };
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
transport.onclose = () => {
|
|
137
|
+
if (transport.sessionId) {
|
|
138
|
+
delete sessions[transport.sessionId];
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const sessionServer = createMcpServer();
|
|
142
|
+
await handleWithSessionConfig(
|
|
143
|
+
apiKey,
|
|
144
|
+
() => sessionServer.connect(transport)
|
|
145
|
+
);
|
|
146
|
+
await handleWithSessionConfig(
|
|
147
|
+
apiKey,
|
|
148
|
+
() => transport.handleRequest(req, res, req.body)
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
res.status(400).json({
|
|
153
|
+
error: "Invalid request \u2014 no session ID or not an initialize request"
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
app.get("/mcp", async (req, res) => {
|
|
157
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
158
|
+
if (sessionId && sessions[sessionId]) {
|
|
159
|
+
const session = sessions[sessionId];
|
|
160
|
+
await handleWithSessionConfig(
|
|
161
|
+
session.apiKey,
|
|
162
|
+
() => session.transport.handleRequest(req, res)
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
res.status(400).json({ error: "Invalid request \u2014 no valid session ID" });
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
app.delete("/mcp", async (req, res) => {
|
|
169
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
170
|
+
if (sessionId && sessions[sessionId]) {
|
|
171
|
+
const session = sessions[sessionId];
|
|
172
|
+
await session.transport.close();
|
|
173
|
+
delete sessions[sessionId];
|
|
174
|
+
res.status(200).json({ status: "session closed" });
|
|
175
|
+
} else {
|
|
176
|
+
res.status(404).json({ error: "Session not found" });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const sseSessions = {};
|
|
180
|
+
app.get("/sse", async (req, res) => {
|
|
181
|
+
const apiKey = extractBearerToken(req) || req.query["apiKey"] || null;
|
|
182
|
+
if (!apiKey) {
|
|
183
|
+
res.status(401).json({
|
|
184
|
+
error: "Authorization: Bearer <LANGWATCH_API_KEY> header or ?apiKey= query parameter required"
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const transport = new SSEServerTransport("/messages", res);
|
|
189
|
+
sseSessions[transport.sessionId] = { transport, apiKey };
|
|
190
|
+
const sessionServer = createMcpServer();
|
|
191
|
+
res.on("close", () => {
|
|
192
|
+
delete sseSessions[transport.sessionId];
|
|
193
|
+
});
|
|
194
|
+
await handleWithSessionConfig(
|
|
195
|
+
apiKey,
|
|
196
|
+
() => sessionServer.connect(transport)
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
const handleSseMessage = async (req, res) => {
|
|
200
|
+
const sessionId = req.query["sessionId"];
|
|
201
|
+
if (!sessionId || !sseSessions[sessionId]) {
|
|
202
|
+
res.status(400).json({ error: "Invalid or missing session ID" });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const session = sseSessions[sessionId];
|
|
206
|
+
await handleWithSessionConfig(
|
|
207
|
+
session.apiKey,
|
|
208
|
+
() => session.transport.handlePostMessage(req, res, req.body)
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
app.post("/messages", handleSseMessage);
|
|
212
|
+
app.post("/sse/messages", handleSseMessage);
|
|
213
|
+
return new Promise((resolve) => {
|
|
214
|
+
const server = app.listen(port, "0.0.0.0", () => {
|
|
215
|
+
const addr = server.address();
|
|
216
|
+
const resolvedPort = typeof addr === "object" && addr ? addr.port : port;
|
|
217
|
+
resolve({ server, port: resolvedPort });
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
startHttpServer
|
|
223
|
+
};
|
|
224
|
+
//# sourceMappingURL=http-server-RSTXN4CN.js.map
|