mcp-codex-worker 0.1.0
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/README.md +135 -0
- package/bin/mcp-codex-worker.mjs +17 -0
- package/dist/src/app.d.ts +29 -0
- package/dist/src/app.js +353 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/config/defaults.d.ts +11 -0
- package/dist/src/config/defaults.js +12 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +64 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/tool-definitions.d.ts +180 -0
- package/dist/src/mcp/tool-definitions.js +241 -0
- package/dist/src/mcp/tool-definitions.js.map +1 -0
- package/dist/src/services/app-server-client.d.ts +65 -0
- package/dist/src/services/app-server-client.js +511 -0
- package/dist/src/services/app-server-client.js.map +1 -0
- package/dist/src/services/codex-runtime.d.ts +84 -0
- package/dist/src/services/codex-runtime.js +371 -0
- package/dist/src/services/codex-runtime.js.map +1 -0
- package/dist/src/services/fleet-mode.d.ts +3 -0
- package/dist/src/services/fleet-mode.js +21 -0
- package/dist/src/services/fleet-mode.js.map +1 -0
- package/dist/src/services/model-catalog.d.ts +22 -0
- package/dist/src/services/model-catalog.js +51 -0
- package/dist/src/services/model-catalog.js.map +1 -0
- package/dist/src/services/profile-manager.d.ts +29 -0
- package/dist/src/services/profile-manager.js +82 -0
- package/dist/src/services/profile-manager.js.map +1 -0
- package/dist/src/types/codex.d.ts +50 -0
- package/dist/src/types/codex.js +2 -0
- package/dist/src/types/codex.js.map +1 -0
- package/package.json +53 -0
- package/src/app.ts +417 -0
- package/src/config/defaults.ts +14 -0
- package/src/index.ts +84 -0
- package/src/mcp/tool-definitions.ts +280 -0
- package/src/protocol/AbsolutePathBuf.ts +14 -0
- package/src/protocol/AgentPath.ts +5 -0
- package/src/protocol/ApplyPatchApprovalParams.ts +21 -0
- package/src/protocol/ApplyPatchApprovalResponse.ts +6 -0
- package/src/protocol/AuthMode.ts +8 -0
- package/src/protocol/ClientInfo.ts +5 -0
- package/src/protocol/ClientNotification.ts +5 -0
- package/src/protocol/ClientRequest.ts +67 -0
- package/src/protocol/CollaborationMode.ts +10 -0
- package/src/protocol/ContentItem.ts +5 -0
- package/src/protocol/ConversationGitInfo.ts +5 -0
- package/src/protocol/ConversationSummary.ts +8 -0
- package/src/protocol/ExecCommandApprovalParams.ts +16 -0
- package/src/protocol/ExecCommandApprovalResponse.ts +6 -0
- package/src/protocol/ExecPolicyAmendment.ts +12 -0
- package/src/protocol/FileChange.ts +5 -0
- package/src/protocol/ForcedLoginMethod.ts +5 -0
- package/src/protocol/FunctionCallOutputBody.ts +6 -0
- package/src/protocol/FunctionCallOutputContentItem.ts +10 -0
- package/src/protocol/FuzzyFileSearchMatchType.ts +5 -0
- package/src/protocol/FuzzyFileSearchParams.ts +5 -0
- package/src/protocol/FuzzyFileSearchResponse.ts +6 -0
- package/src/protocol/FuzzyFileSearchResult.ts +9 -0
- package/src/protocol/FuzzyFileSearchSessionCompletedNotification.ts +5 -0
- package/src/protocol/FuzzyFileSearchSessionUpdatedNotification.ts +6 -0
- package/src/protocol/GetAuthStatusParams.ts +5 -0
- package/src/protocol/GetAuthStatusResponse.ts +6 -0
- package/src/protocol/GetConversationSummaryParams.ts +6 -0
- package/src/protocol/GetConversationSummaryResponse.ts +6 -0
- package/src/protocol/GhostCommit.ts +8 -0
- package/src/protocol/GitDiffToRemoteParams.ts +5 -0
- package/src/protocol/GitDiffToRemoteResponse.ts +6 -0
- package/src/protocol/GitSha.ts +5 -0
- package/src/protocol/ImageDetail.ts +5 -0
- package/src/protocol/InitializeCapabilities.ts +17 -0
- package/src/protocol/InitializeParams.ts +7 -0
- package/src/protocol/InitializeResponse.ts +20 -0
- package/src/protocol/InputModality.ts +8 -0
- package/src/protocol/LocalShellAction.ts +6 -0
- package/src/protocol/LocalShellExecAction.ts +5 -0
- package/src/protocol/LocalShellStatus.ts +5 -0
- package/src/protocol/MessagePhase.ts +11 -0
- package/src/protocol/ModeKind.ts +8 -0
- package/src/protocol/NetworkPolicyAmendment.ts +6 -0
- package/src/protocol/NetworkPolicyRuleAction.ts +5 -0
- package/src/protocol/ParsedCommand.ts +12 -0
- package/src/protocol/Personality.ts +5 -0
- package/src/protocol/PlanType.ts +5 -0
- package/src/protocol/RealtimeConversationVersion.ts +5 -0
- package/src/protocol/ReasoningEffort.ts +8 -0
- package/src/protocol/ReasoningItemContent.ts +5 -0
- package/src/protocol/ReasoningItemReasoningSummary.ts +5 -0
- package/src/protocol/ReasoningSummary.ts +10 -0
- package/src/protocol/RequestId.ts +5 -0
- package/src/protocol/Resource.ts +9 -0
- package/src/protocol/ResourceTemplate.ts +9 -0
- package/src/protocol/ResponseItem.ts +18 -0
- package/src/protocol/ReviewDecision.ts +10 -0
- package/src/protocol/ServerNotification.ts +60 -0
- package/src/protocol/ServerRequest.ts +18 -0
- package/src/protocol/ServiceTier.ts +5 -0
- package/src/protocol/SessionSource.ts +6 -0
- package/src/protocol/Settings.ts +9 -0
- package/src/protocol/SubAgentSource.ts +7 -0
- package/src/protocol/ThreadId.ts +5 -0
- package/src/protocol/Tool.ts +9 -0
- package/src/protocol/Verbosity.ts +9 -0
- package/src/protocol/WebSearchAction.ts +5 -0
- package/src/protocol/WebSearchContextSize.ts +5 -0
- package/src/protocol/WebSearchLocation.ts +5 -0
- package/src/protocol/WebSearchMode.ts +5 -0
- package/src/protocol/WebSearchToolConfig.ts +7 -0
- package/src/protocol/index.ts +75 -0
- package/src/protocol/serde_json/JsonValue.ts +5 -0
- package/src/protocol/v2/Account.ts +6 -0
- package/src/protocol/v2/AccountLoginCompletedNotification.ts +5 -0
- package/src/protocol/v2/AccountRateLimitsUpdatedNotification.ts +6 -0
- package/src/protocol/v2/AccountUpdatedNotification.ts +7 -0
- package/src/protocol/v2/AdditionalFileSystemPermissions.ts +6 -0
- package/src/protocol/v2/AdditionalNetworkPermissions.ts +5 -0
- package/src/protocol/v2/AdditionalPermissionProfile.ts +7 -0
- package/src/protocol/v2/AgentMessageDeltaNotification.ts +5 -0
- package/src/protocol/v2/AnalyticsConfig.ts +6 -0
- package/src/protocol/v2/AppBranding.ts +8 -0
- package/src/protocol/v2/AppInfo.ts +19 -0
- package/src/protocol/v2/AppListUpdatedNotification.ts +9 -0
- package/src/protocol/v2/AppMetadata.ts +7 -0
- package/src/protocol/v2/AppReview.ts +5 -0
- package/src/protocol/v2/AppScreenshot.ts +5 -0
- package/src/protocol/v2/AppSummary.ts +8 -0
- package/src/protocol/v2/AppToolApproval.ts +5 -0
- package/src/protocol/v2/AppToolsConfig.ts +6 -0
- package/src/protocol/v2/ApprovalsReviewer.ts +12 -0
- package/src/protocol/v2/AppsConfig.ts +8 -0
- package/src/protocol/v2/AppsDefaultConfig.ts +5 -0
- package/src/protocol/v2/AppsListParams.ts +24 -0
- package/src/protocol/v2/AppsListResponse.ts +14 -0
- package/src/protocol/v2/AskForApproval.ts +5 -0
- package/src/protocol/v2/ByteRange.ts +5 -0
- package/src/protocol/v2/CancelLoginAccountParams.ts +5 -0
- package/src/protocol/v2/CancelLoginAccountResponse.ts +6 -0
- package/src/protocol/v2/CancelLoginAccountStatus.ts +5 -0
- package/src/protocol/v2/ChatgptAuthTokensRefreshParams.ts +16 -0
- package/src/protocol/v2/ChatgptAuthTokensRefreshReason.ts +5 -0
- package/src/protocol/v2/ChatgptAuthTokensRefreshResponse.ts +5 -0
- package/src/protocol/v2/CodexErrorInfo.ts +12 -0
- package/src/protocol/v2/CollabAgentState.ts +6 -0
- package/src/protocol/v2/CollabAgentStatus.ts +5 -0
- package/src/protocol/v2/CollabAgentTool.ts +5 -0
- package/src/protocol/v2/CollabAgentToolCallStatus.ts +5 -0
- package/src/protocol/v2/CollaborationModeMask.ts +10 -0
- package/src/protocol/v2/CommandAction.ts +5 -0
- package/src/protocol/v2/CommandExecOutputDeltaNotification.ts +30 -0
- package/src/protocol/v2/CommandExecOutputStream.ts +8 -0
- package/src/protocol/v2/CommandExecParams.ts +97 -0
- package/src/protocol/v2/CommandExecResizeParams.ts +18 -0
- package/src/protocol/v2/CommandExecResizeResponse.ts +8 -0
- package/src/protocol/v2/CommandExecResponse.ts +24 -0
- package/src/protocol/v2/CommandExecTerminalSize.ts +16 -0
- package/src/protocol/v2/CommandExecTerminateParams.ts +13 -0
- package/src/protocol/v2/CommandExecTerminateResponse.ts +8 -0
- package/src/protocol/v2/CommandExecWriteParams.ts +22 -0
- package/src/protocol/v2/CommandExecWriteResponse.ts +8 -0
- package/src/protocol/v2/CommandExecutionApprovalDecision.ts +7 -0
- package/src/protocol/v2/CommandExecutionOutputDeltaNotification.ts +5 -0
- package/src/protocol/v2/CommandExecutionRequestApprovalParams.ts +57 -0
- package/src/protocol/v2/CommandExecutionRequestApprovalResponse.ts +6 -0
- package/src/protocol/v2/CommandExecutionSource.ts +5 -0
- package/src/protocol/v2/CommandExecutionStatus.ts +5 -0
- package/src/protocol/v2/Config.ts +23 -0
- package/src/protocol/v2/ConfigBatchWriteParams.ts +14 -0
- package/src/protocol/v2/ConfigEdit.ts +7 -0
- package/src/protocol/v2/ConfigLayer.ts +7 -0
- package/src/protocol/v2/ConfigLayerMetadata.ts +6 -0
- package/src/protocol/v2/ConfigLayerSource.ts +16 -0
- package/src/protocol/v2/ConfigReadParams.ts +11 -0
- package/src/protocol/v2/ConfigReadResponse.ts +8 -0
- package/src/protocol/v2/ConfigRequirements.ts +9 -0
- package/src/protocol/v2/ConfigRequirementsReadResponse.ts +10 -0
- package/src/protocol/v2/ConfigValueWriteParams.ts +11 -0
- package/src/protocol/v2/ConfigWarningNotification.ts +22 -0
- package/src/protocol/v2/ConfigWriteResponse.ts +12 -0
- package/src/protocol/v2/ContextCompactedNotification.ts +8 -0
- package/src/protocol/v2/CreditsSnapshot.ts +5 -0
- package/src/protocol/v2/DeprecationNoticeNotification.ts +13 -0
- package/src/protocol/v2/DynamicToolCallOutputContentItem.ts +5 -0
- package/src/protocol/v2/DynamicToolCallParams.ts +6 -0
- package/src/protocol/v2/DynamicToolCallResponse.ts +6 -0
- package/src/protocol/v2/DynamicToolCallStatus.ts +5 -0
- package/src/protocol/v2/DynamicToolSpec.ts +6 -0
- package/src/protocol/v2/ErrorNotification.ts +6 -0
- package/src/protocol/v2/ExecPolicyAmendment.ts +5 -0
- package/src/protocol/v2/ExperimentalFeature.ts +37 -0
- package/src/protocol/v2/ExperimentalFeatureEnablementSetParams.ts +12 -0
- package/src/protocol/v2/ExperimentalFeatureEnablementSetResponse.ts +9 -0
- package/src/protocol/v2/ExperimentalFeatureListParams.ts +13 -0
- package/src/protocol/v2/ExperimentalFeatureListResponse.ts +11 -0
- package/src/protocol/v2/ExperimentalFeatureStage.ts +5 -0
- package/src/protocol/v2/ExternalAgentConfigDetectParams.ts +13 -0
- package/src/protocol/v2/ExternalAgentConfigDetectResponse.ts +6 -0
- package/src/protocol/v2/ExternalAgentConfigImportParams.ts +6 -0
- package/src/protocol/v2/ExternalAgentConfigImportResponse.ts +5 -0
- package/src/protocol/v2/ExternalAgentConfigMigrationItem.ts +10 -0
- package/src/protocol/v2/ExternalAgentConfigMigrationItemType.ts +5 -0
- package/src/protocol/v2/FeedbackUploadParams.ts +5 -0
- package/src/protocol/v2/FeedbackUploadResponse.ts +5 -0
- package/src/protocol/v2/FileChangeApprovalDecision.ts +5 -0
- package/src/protocol/v2/FileChangeOutputDeltaNotification.ts +5 -0
- package/src/protocol/v2/FileChangeRequestApprovalParams.ts +14 -0
- package/src/protocol/v2/FileChangeRequestApprovalResponse.ts +6 -0
- package/src/protocol/v2/FileUpdateChange.ts +6 -0
- package/src/protocol/v2/FsChangedNotification.ts +17 -0
- package/src/protocol/v2/FsCopyParams.ts +21 -0
- package/src/protocol/v2/FsCopyResponse.ts +8 -0
- package/src/protocol/v2/FsCreateDirectoryParams.ts +17 -0
- package/src/protocol/v2/FsCreateDirectoryResponse.ts +8 -0
- package/src/protocol/v2/FsGetMetadataParams.ts +13 -0
- package/src/protocol/v2/FsGetMetadataResponse.ts +24 -0
- package/src/protocol/v2/FsReadDirectoryEntry.ts +20 -0
- package/src/protocol/v2/FsReadDirectoryParams.ts +13 -0
- package/src/protocol/v2/FsReadDirectoryResponse.ts +13 -0
- package/src/protocol/v2/FsReadFileParams.ts +13 -0
- package/src/protocol/v2/FsReadFileResponse.ts +12 -0
- package/src/protocol/v2/FsRemoveParams.ts +21 -0
- package/src/protocol/v2/FsRemoveResponse.ts +8 -0
- package/src/protocol/v2/FsUnwatchParams.ts +12 -0
- package/src/protocol/v2/FsUnwatchResponse.ts +8 -0
- package/src/protocol/v2/FsWatchParams.ts +13 -0
- package/src/protocol/v2/FsWatchResponse.ts +17 -0
- package/src/protocol/v2/FsWriteFileParams.ts +17 -0
- package/src/protocol/v2/FsWriteFileResponse.ts +8 -0
- package/src/protocol/v2/GetAccountParams.ts +13 -0
- package/src/protocol/v2/GetAccountRateLimitsResponse.ts +14 -0
- package/src/protocol/v2/GetAccountResponse.ts +6 -0
- package/src/protocol/v2/GitInfo.ts +5 -0
- package/src/protocol/v2/GrantedPermissionProfile.ts +7 -0
- package/src/protocol/v2/GuardianApprovalReview.ts +12 -0
- package/src/protocol/v2/GuardianApprovalReviewStatus.ts +8 -0
- package/src/protocol/v2/GuardianRiskLevel.ts +8 -0
- package/src/protocol/v2/HookCompletedNotification.ts +6 -0
- package/src/protocol/v2/HookEventName.ts +5 -0
- package/src/protocol/v2/HookExecutionMode.ts +5 -0
- package/src/protocol/v2/HookHandlerType.ts +5 -0
- package/src/protocol/v2/HookOutputEntry.ts +6 -0
- package/src/protocol/v2/HookOutputEntryKind.ts +5 -0
- package/src/protocol/v2/HookPromptFragment.ts +5 -0
- package/src/protocol/v2/HookRunStatus.ts +5 -0
- package/src/protocol/v2/HookRunSummary.ts +11 -0
- package/src/protocol/v2/HookScope.ts +5 -0
- package/src/protocol/v2/HookStartedNotification.ts +6 -0
- package/src/protocol/v2/ItemCompletedNotification.ts +6 -0
- package/src/protocol/v2/ItemGuardianApprovalReviewCompletedNotification.ts +15 -0
- package/src/protocol/v2/ItemGuardianApprovalReviewStartedNotification.ts +15 -0
- package/src/protocol/v2/ItemStartedNotification.ts +6 -0
- package/src/protocol/v2/ListMcpServerStatusParams.ts +13 -0
- package/src/protocol/v2/ListMcpServerStatusResponse.ts +11 -0
- package/src/protocol/v2/LoginAccountParams.ts +21 -0
- package/src/protocol/v2/LoginAccountResponse.ts +17 -0
- package/src/protocol/v2/LogoutAccountResponse.ts +5 -0
- package/src/protocol/v2/MarketplaceInterface.ts +5 -0
- package/src/protocol/v2/MarketplaceLoadErrorInfo.ts +6 -0
- package/src/protocol/v2/McpAuthStatus.ts +5 -0
- package/src/protocol/v2/McpElicitationArrayType.ts +5 -0
- package/src/protocol/v2/McpElicitationBooleanSchema.ts +6 -0
- package/src/protocol/v2/McpElicitationBooleanType.ts +5 -0
- package/src/protocol/v2/McpElicitationConstOption.ts +5 -0
- package/src/protocol/v2/McpElicitationEnumSchema.ts +8 -0
- package/src/protocol/v2/McpElicitationLegacyTitledEnumSchema.ts +6 -0
- package/src/protocol/v2/McpElicitationMultiSelectEnumSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationNumberSchema.ts +6 -0
- package/src/protocol/v2/McpElicitationNumberType.ts +5 -0
- package/src/protocol/v2/McpElicitationObjectType.ts +5 -0
- package/src/protocol/v2/McpElicitationPrimitiveSchema.ts +9 -0
- package/src/protocol/v2/McpElicitationSchema.ts +13 -0
- package/src/protocol/v2/McpElicitationSingleSelectEnumSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationStringFormat.ts +5 -0
- package/src/protocol/v2/McpElicitationStringSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationStringType.ts +5 -0
- package/src/protocol/v2/McpElicitationTitledEnumItems.ts +6 -0
- package/src/protocol/v2/McpElicitationTitledMultiSelectEnumSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationTitledSingleSelectEnumSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationUntitledEnumItems.ts +6 -0
- package/src/protocol/v2/McpElicitationUntitledMultiSelectEnumSchema.ts +7 -0
- package/src/protocol/v2/McpElicitationUntitledSingleSelectEnumSchema.ts +6 -0
- package/src/protocol/v2/McpServerElicitationAction.ts +5 -0
- package/src/protocol/v2/McpServerElicitationRequestParams.ts +16 -0
- package/src/protocol/v2/McpServerElicitationRequestResponse.ts +17 -0
- package/src/protocol/v2/McpServerOauthLoginCompletedNotification.ts +5 -0
- package/src/protocol/v2/McpServerOauthLoginParams.ts +5 -0
- package/src/protocol/v2/McpServerOauthLoginResponse.ts +5 -0
- package/src/protocol/v2/McpServerRefreshResponse.ts +5 -0
- package/src/protocol/v2/McpServerStartupState.ts +5 -0
- package/src/protocol/v2/McpServerStatus.ts +9 -0
- package/src/protocol/v2/McpServerStatusUpdatedNotification.ts +6 -0
- package/src/protocol/v2/McpToolCallError.ts +5 -0
- package/src/protocol/v2/McpToolCallProgressNotification.ts +5 -0
- package/src/protocol/v2/McpToolCallResult.ts +6 -0
- package/src/protocol/v2/McpToolCallStatus.ts +5 -0
- package/src/protocol/v2/MemoryCitation.ts +6 -0
- package/src/protocol/v2/MemoryCitationEntry.ts +5 -0
- package/src/protocol/v2/MergeStrategy.ts +5 -0
- package/src/protocol/v2/Model.ts +10 -0
- package/src/protocol/v2/ModelAvailabilityNux.ts +5 -0
- package/src/protocol/v2/ModelListParams.ts +17 -0
- package/src/protocol/v2/ModelListResponse.ts +11 -0
- package/src/protocol/v2/ModelRerouteReason.ts +5 -0
- package/src/protocol/v2/ModelReroutedNotification.ts +6 -0
- package/src/protocol/v2/ModelUpgradeInfo.ts +5 -0
- package/src/protocol/v2/NetworkAccess.ts +5 -0
- package/src/protocol/v2/NetworkApprovalContext.ts +6 -0
- package/src/protocol/v2/NetworkApprovalProtocol.ts +5 -0
- package/src/protocol/v2/NetworkDomainPermission.ts +5 -0
- package/src/protocol/v2/NetworkPolicyAmendment.ts +6 -0
- package/src/protocol/v2/NetworkPolicyRuleAction.ts +5 -0
- package/src/protocol/v2/NetworkRequirements.ts +32 -0
- package/src/protocol/v2/NetworkUnixSocketPermission.ts +5 -0
- package/src/protocol/v2/NonSteerableTurnKind.ts +5 -0
- package/src/protocol/v2/OverriddenMetadata.ts +7 -0
- package/src/protocol/v2/PatchApplyStatus.ts +5 -0
- package/src/protocol/v2/PatchChangeKind.ts +5 -0
- package/src/protocol/v2/PermissionGrantScope.ts +5 -0
- package/src/protocol/v2/PermissionsRequestApprovalParams.ts +6 -0
- package/src/protocol/v2/PermissionsRequestApprovalResponse.ts +7 -0
- package/src/protocol/v2/PlanDeltaNotification.ts +9 -0
- package/src/protocol/v2/PluginAuthPolicy.ts +5 -0
- package/src/protocol/v2/PluginDetail.ts +9 -0
- package/src/protocol/v2/PluginInstallParams.ts +10 -0
- package/src/protocol/v2/PluginInstallPolicy.ts +5 -0
- package/src/protocol/v2/PluginInstallResponse.ts +7 -0
- package/src/protocol/v2/PluginInterface.ts +11 -0
- package/src/protocol/v2/PluginListParams.ts +16 -0
- package/src/protocol/v2/PluginListResponse.ts +7 -0
- package/src/protocol/v2/PluginMarketplaceEntry.ts +8 -0
- package/src/protocol/v2/PluginReadParams.ts +6 -0
- package/src/protocol/v2/PluginReadResponse.ts +6 -0
- package/src/protocol/v2/PluginSource.ts +6 -0
- package/src/protocol/v2/PluginSummary.ts +9 -0
- package/src/protocol/v2/PluginUninstallParams.ts +9 -0
- package/src/protocol/v2/PluginUninstallResponse.ts +5 -0
- package/src/protocol/v2/ProfileV2.ts +19 -0
- package/src/protocol/v2/RateLimitSnapshot.ts +8 -0
- package/src/protocol/v2/RateLimitWindow.ts +5 -0
- package/src/protocol/v2/RawResponseItemCompletedNotification.ts +6 -0
- package/src/protocol/v2/ReadOnlyAccess.ts +6 -0
- package/src/protocol/v2/ReasoningEffortOption.ts +6 -0
- package/src/protocol/v2/ReasoningSummaryPartAddedNotification.ts +5 -0
- package/src/protocol/v2/ReasoningSummaryTextDeltaNotification.ts +5 -0
- package/src/protocol/v2/ReasoningTextDeltaNotification.ts +5 -0
- package/src/protocol/v2/RequestPermissionProfile.ts +7 -0
- package/src/protocol/v2/ResidencyRequirement.ts +5 -0
- package/src/protocol/v2/ReviewDelivery.ts +5 -0
- package/src/protocol/v2/ReviewStartParams.ts +12 -0
- package/src/protocol/v2/ReviewStartResponse.ts +13 -0
- package/src/protocol/v2/ReviewTarget.ts +9 -0
- package/src/protocol/v2/SandboxMode.ts +5 -0
- package/src/protocol/v2/SandboxPolicy.ts +8 -0
- package/src/protocol/v2/SandboxWorkspaceWrite.ts +5 -0
- package/src/protocol/v2/ServerRequestResolvedNotification.ts +6 -0
- package/src/protocol/v2/SessionSource.ts +6 -0
- package/src/protocol/v2/SkillDependencies.ts +6 -0
- package/src/protocol/v2/SkillErrorInfo.ts +5 -0
- package/src/protocol/v2/SkillInterface.ts +5 -0
- package/src/protocol/v2/SkillMetadata.ts +12 -0
- package/src/protocol/v2/SkillScope.ts +5 -0
- package/src/protocol/v2/SkillSummary.ts +6 -0
- package/src/protocol/v2/SkillToolDependency.ts +5 -0
- package/src/protocol/v2/SkillsChangedNotification.ts +11 -0
- package/src/protocol/v2/SkillsConfigWriteParams.ts +14 -0
- package/src/protocol/v2/SkillsConfigWriteResponse.ts +5 -0
- package/src/protocol/v2/SkillsListEntry.ts +7 -0
- package/src/protocol/v2/SkillsListExtraRootsForCwd.ts +5 -0
- package/src/protocol/v2/SkillsListParams.ts +18 -0
- package/src/protocol/v2/SkillsListResponse.ts +6 -0
- package/src/protocol/v2/TerminalInteractionNotification.ts +5 -0
- package/src/protocol/v2/TextElement.ts +14 -0
- package/src/protocol/v2/TextPosition.ts +13 -0
- package/src/protocol/v2/TextRange.ts +6 -0
- package/src/protocol/v2/Thread.ts +72 -0
- package/src/protocol/v2/ThreadActiveFlag.ts +5 -0
- package/src/protocol/v2/ThreadArchiveParams.ts +5 -0
- package/src/protocol/v2/ThreadArchiveResponse.ts +5 -0
- package/src/protocol/v2/ThreadArchivedNotification.ts +5 -0
- package/src/protocol/v2/ThreadClosedNotification.ts +5 -0
- package/src/protocol/v2/ThreadCompactStartParams.ts +5 -0
- package/src/protocol/v2/ThreadCompactStartResponse.ts +5 -0
- package/src/protocol/v2/ThreadForkParams.ts +34 -0
- package/src/protocol/v2/ThreadForkResponse.ts +15 -0
- package/src/protocol/v2/ThreadItem.ts +100 -0
- package/src/protocol/v2/ThreadListParams.ts +43 -0
- package/src/protocol/v2/ThreadListResponse.ts +11 -0
- package/src/protocol/v2/ThreadLoadedListParams.ts +13 -0
- package/src/protocol/v2/ThreadLoadedListResponse.ts +14 -0
- package/src/protocol/v2/ThreadMetadataGitInfoUpdateParams.ts +20 -0
- package/src/protocol/v2/ThreadMetadataUpdateParams.ts +12 -0
- package/src/protocol/v2/ThreadMetadataUpdateResponse.ts +6 -0
- package/src/protocol/v2/ThreadNameUpdatedNotification.ts +5 -0
- package/src/protocol/v2/ThreadReadParams.ts +9 -0
- package/src/protocol/v2/ThreadReadResponse.ts +6 -0
- package/src/protocol/v2/ThreadRealtimeAudioChunk.ts +8 -0
- package/src/protocol/v2/ThreadRealtimeClosedNotification.ts +8 -0
- package/src/protocol/v2/ThreadRealtimeErrorNotification.ts +8 -0
- package/src/protocol/v2/ThreadRealtimeItemAddedNotification.ts +9 -0
- package/src/protocol/v2/ThreadRealtimeOutputAudioDeltaNotification.ts +9 -0
- package/src/protocol/v2/ThreadRealtimeStartedNotification.ts +9 -0
- package/src/protocol/v2/ThreadRealtimeTranscriptUpdatedNotification.ts +9 -0
- package/src/protocol/v2/ThreadResumeParams.ts +43 -0
- package/src/protocol/v2/ThreadResumeResponse.ts +15 -0
- package/src/protocol/v2/ThreadRollbackParams.ts +12 -0
- package/src/protocol/v2/ThreadRollbackResponse.ts +14 -0
- package/src/protocol/v2/ThreadSetNameParams.ts +5 -0
- package/src/protocol/v2/ThreadSetNameResponse.ts +5 -0
- package/src/protocol/v2/ThreadShellCommandParams.ts +12 -0
- package/src/protocol/v2/ThreadShellCommandResponse.ts +5 -0
- package/src/protocol/v2/ThreadSortKey.ts +5 -0
- package/src/protocol/v2/ThreadSourceKind.ts +5 -0
- package/src/protocol/v2/ThreadStartParams.ts +23 -0
- package/src/protocol/v2/ThreadStartResponse.ts +15 -0
- package/src/protocol/v2/ThreadStartedNotification.ts +6 -0
- package/src/protocol/v2/ThreadStatus.ts +6 -0
- package/src/protocol/v2/ThreadStatusChangedNotification.ts +6 -0
- package/src/protocol/v2/ThreadTokenUsage.ts +6 -0
- package/src/protocol/v2/ThreadTokenUsageUpdatedNotification.ts +6 -0
- package/src/protocol/v2/ThreadUnarchiveParams.ts +5 -0
- package/src/protocol/v2/ThreadUnarchiveResponse.ts +6 -0
- package/src/protocol/v2/ThreadUnarchivedNotification.ts +5 -0
- package/src/protocol/v2/ThreadUnsubscribeParams.ts +5 -0
- package/src/protocol/v2/ThreadUnsubscribeResponse.ts +6 -0
- package/src/protocol/v2/ThreadUnsubscribeStatus.ts +5 -0
- package/src/protocol/v2/TokenUsageBreakdown.ts +5 -0
- package/src/protocol/v2/ToolRequestUserInputAnswer.ts +8 -0
- package/src/protocol/v2/ToolRequestUserInputOption.ts +8 -0
- package/src/protocol/v2/ToolRequestUserInputParams.ts +9 -0
- package/src/protocol/v2/ToolRequestUserInputQuestion.ts +9 -0
- package/src/protocol/v2/ToolRequestUserInputResponse.ts +9 -0
- package/src/protocol/v2/ToolsV2.ts +6 -0
- package/src/protocol/v2/Turn.ts +18 -0
- package/src/protocol/v2/TurnCompletedNotification.ts +6 -0
- package/src/protocol/v2/TurnDiffUpdatedNotification.ts +9 -0
- package/src/protocol/v2/TurnError.ts +6 -0
- package/src/protocol/v2/TurnInterruptParams.ts +5 -0
- package/src/protocol/v2/TurnInterruptResponse.ts +5 -0
- package/src/protocol/v2/TurnPlanStep.ts +6 -0
- package/src/protocol/v2/TurnPlanStepStatus.ts +5 -0
- package/src/protocol/v2/TurnPlanUpdatedNotification.ts +6 -0
- package/src/protocol/v2/TurnStartParams.ts +54 -0
- package/src/protocol/v2/TurnStartResponse.ts +6 -0
- package/src/protocol/v2/TurnStartedNotification.ts +6 -0
- package/src/protocol/v2/TurnStatus.ts +5 -0
- package/src/protocol/v2/TurnSteerParams.ts +11 -0
- package/src/protocol/v2/TurnSteerResponse.ts +5 -0
- package/src/protocol/v2/UserInput.ts +10 -0
- package/src/protocol/v2/WebSearchAction.ts +5 -0
- package/src/protocol/v2/WindowsSandboxSetupCompletedNotification.ts +6 -0
- package/src/protocol/v2/WindowsSandboxSetupMode.ts +5 -0
- package/src/protocol/v2/WindowsSandboxSetupStartParams.ts +7 -0
- package/src/protocol/v2/WindowsSandboxSetupStartResponse.ts +5 -0
- package/src/protocol/v2/WindowsWorldWritableWarningNotification.ts +5 -0
- package/src/protocol/v2/WriteStatus.ts +5 -0
- package/src/protocol/v2/index.ts +346 -0
- package/src/services/app-server-client.ts +636 -0
- package/src/services/codex-runtime.ts +500 -0
- package/src/services/fleet-mode.ts +29 -0
- package/src/services/model-catalog.ts +86 -0
- package/src/services/profile-manager.ts +113 -0
- package/src/types/codex.ts +57 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type RequestId = string | number;
|
|
2
|
+
export interface JsonLineRequest {
|
|
3
|
+
method: string;
|
|
4
|
+
id: RequestId;
|
|
5
|
+
params: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonLineNotification {
|
|
8
|
+
method: string;
|
|
9
|
+
params: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface JsonLineResponse {
|
|
12
|
+
id: RequestId;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
error?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export type JsonLineMessage = JsonLineRequest | JsonLineNotification | JsonLineResponse;
|
|
17
|
+
export interface InitializeParams {
|
|
18
|
+
clientInfo: {
|
|
19
|
+
name: string;
|
|
20
|
+
title: string | null;
|
|
21
|
+
version: string;
|
|
22
|
+
};
|
|
23
|
+
capabilities: {
|
|
24
|
+
experimentalApi: boolean;
|
|
25
|
+
optOutNotificationMethods?: string[] | null;
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
export interface PendingServerRequest {
|
|
29
|
+
id: RequestId;
|
|
30
|
+
method: string;
|
|
31
|
+
params: unknown;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
resolvedAt?: string | undefined;
|
|
34
|
+
response?: unknown;
|
|
35
|
+
resolutionError?: string | undefined;
|
|
36
|
+
status: 'pending' | 'resolved' | 'failed';
|
|
37
|
+
}
|
|
38
|
+
export interface RuntimeOperation {
|
|
39
|
+
operationId: string;
|
|
40
|
+
requestId: RequestId;
|
|
41
|
+
method: string;
|
|
42
|
+
threadId?: string | undefined;
|
|
43
|
+
turnId?: string | undefined;
|
|
44
|
+
startedAt: string;
|
|
45
|
+
completedAt?: string | undefined;
|
|
46
|
+
status: 'running' | 'completed' | 'failed';
|
|
47
|
+
result?: unknown;
|
|
48
|
+
error?: string;
|
|
49
|
+
pendingRequestIds: RequestId[];
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../../src/types/codex.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-codex-worker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server bridge for Codex app-server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcp-codex-worker": "bin/mcp-codex-worker.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"dist/src",
|
|
13
|
+
"src",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"clean": "rm -rf dist",
|
|
19
|
+
"prepack": "npm run build",
|
|
20
|
+
"serve": "node --import tsx src/index.ts",
|
|
21
|
+
"smoke": "node --import tsx scripts/smoke.ts",
|
|
22
|
+
"test": "npm run test:unit",
|
|
23
|
+
"test:unit": "node --import tsx --test test/**/*.test.ts"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"mcp",
|
|
27
|
+
"codex",
|
|
28
|
+
"app-server"
|
|
29
|
+
],
|
|
30
|
+
"author": "Yigit Konur",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/yigitkonur/mcp-codex-worker.git"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/yigitkonur/mcp-codex-worker#readme",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
45
|
+
"tsx": "^4.20.6",
|
|
46
|
+
"zod": "^3.24.4"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.15.3",
|
|
50
|
+
"typescript": "^5.8.3"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createToolDefinitions,
|
|
3
|
+
type RequestRespondInput,
|
|
4
|
+
type ThreadListInput,
|
|
5
|
+
type ThreadReadInput,
|
|
6
|
+
type ThreadResumeInput,
|
|
7
|
+
type ThreadStartInput,
|
|
8
|
+
type ToolDefinition,
|
|
9
|
+
type TurnInterruptInput,
|
|
10
|
+
type TurnStartInput,
|
|
11
|
+
type TurnSteerInput,
|
|
12
|
+
type WaitInput,
|
|
13
|
+
} from './mcp/tool-definitions.js';
|
|
14
|
+
import { OPERATION_POLL_INTERVAL_MS, REQUEST_TIMEOUT_MS } from './config/defaults.js';
|
|
15
|
+
import { CodexRuntime } from './services/codex-runtime.js';
|
|
16
|
+
|
|
17
|
+
export interface ResourceDefinition {
|
|
18
|
+
uri: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class CodexWorkerApp {
|
|
25
|
+
private readonly runtime = new CodexRuntime();
|
|
26
|
+
|
|
27
|
+
async initialize(): Promise<void> {}
|
|
28
|
+
|
|
29
|
+
async shutdown(): Promise<void> {
|
|
30
|
+
await this.runtime.shutdown();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async listTools(): Promise<ToolDefinition[]> {
|
|
34
|
+
try {
|
|
35
|
+
const modelIds = await this.runtime.listVisibleModelIds();
|
|
36
|
+
return createToolDefinitions(modelIds);
|
|
37
|
+
} catch {
|
|
38
|
+
return createToolDefinitions([]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
listResources(): ResourceDefinition[] {
|
|
43
|
+
const base: ResourceDefinition[] = [
|
|
44
|
+
{
|
|
45
|
+
uri: 'codex://threads',
|
|
46
|
+
name: 'Codex Threads',
|
|
47
|
+
description: 'Latest threads from `thread/list`',
|
|
48
|
+
mimeType: 'application/json',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
uri: 'codex://models',
|
|
52
|
+
name: 'Codex Models',
|
|
53
|
+
description: 'Visible models from `model/list`',
|
|
54
|
+
mimeType: 'application/json',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
uri: 'codex://account',
|
|
58
|
+
name: 'Codex Account',
|
|
59
|
+
description: 'Account data from `account/read`',
|
|
60
|
+
mimeType: 'application/json',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
uri: 'codex://requests',
|
|
64
|
+
name: 'Codex Requests',
|
|
65
|
+
description: 'Pending server requests from app-server',
|
|
66
|
+
mimeType: 'application/json',
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
for (const threadId of this.runtime.listKnownThreadIds()) {
|
|
71
|
+
base.push(
|
|
72
|
+
{
|
|
73
|
+
uri: `codex://thread/${threadId}`,
|
|
74
|
+
name: `Thread ${threadId}`,
|
|
75
|
+
description: 'Thread from `thread/read`',
|
|
76
|
+
mimeType: 'application/json',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
uri: `codex://thread/${threadId}/events`,
|
|
80
|
+
name: `Thread ${threadId} events`,
|
|
81
|
+
description: 'Observed notifications for this thread',
|
|
82
|
+
mimeType: 'application/json',
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return base;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async readResource(uri: string): Promise<{ mimeType: string; text: string }> {
|
|
91
|
+
if (uri === 'codex://threads') {
|
|
92
|
+
const response = await this.runtime.request('thread/list', { limit: 50 }) as {
|
|
93
|
+
data?: Array<{ id?: string }>;
|
|
94
|
+
};
|
|
95
|
+
for (const row of response.data ?? []) {
|
|
96
|
+
if (typeof row.id === 'string') {
|
|
97
|
+
this.runtime.rememberThreadId(row.id);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
mimeType: 'application/json',
|
|
102
|
+
text: JSON.stringify(response, null, 2),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (uri === 'codex://models') {
|
|
107
|
+
const response = {
|
|
108
|
+
data: await this.runtime.listModels(false),
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
mimeType: 'application/json',
|
|
112
|
+
text: JSON.stringify(response, null, 2),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (uri === 'codex://account') {
|
|
117
|
+
const [account, limits] = await Promise.all([
|
|
118
|
+
this.runtime.request('account/read', {}),
|
|
119
|
+
this.runtime.request('account/rateLimits/read', {}),
|
|
120
|
+
]);
|
|
121
|
+
return {
|
|
122
|
+
mimeType: 'application/json',
|
|
123
|
+
text: JSON.stringify({ account, rate_limits: limits }, null, 2),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (uri === 'codex://requests') {
|
|
128
|
+
return {
|
|
129
|
+
mimeType: 'application/json',
|
|
130
|
+
text: JSON.stringify({
|
|
131
|
+
requests: this.runtime.getPendingServerRequests(false),
|
|
132
|
+
}, null, 2),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const threadEventsMatch = /^codex:\/\/thread\/([^/]+)\/events$/.exec(uri);
|
|
137
|
+
if (threadEventsMatch) {
|
|
138
|
+
const threadId = decodeURIComponent(threadEventsMatch[1]!);
|
|
139
|
+
return {
|
|
140
|
+
mimeType: 'application/json',
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
thread_id: threadId,
|
|
143
|
+
events: await this.runtime.getThreadEvents(threadId),
|
|
144
|
+
}, null, 2),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const threadMatch = /^codex:\/\/thread\/([^/]+)$/.exec(uri);
|
|
149
|
+
if (threadMatch) {
|
|
150
|
+
const threadId = decodeURIComponent(threadMatch[1]!);
|
|
151
|
+
const response = await this.runtime.request('thread/read', {
|
|
152
|
+
threadId,
|
|
153
|
+
includeTurns: true,
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
mimeType: 'application/json',
|
|
157
|
+
text: JSON.stringify(response, null, 2),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
mimeType: 'application/json',
|
|
163
|
+
text: JSON.stringify({ error: `Unknown resource URI: ${uri}` }, null, 2),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async callTool(name: string, args: unknown): Promise<string> {
|
|
168
|
+
const tools = await this.listTools();
|
|
169
|
+
const tool = tools.find((candidate) => candidate.name === name);
|
|
170
|
+
if (!tool) {
|
|
171
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
172
|
+
}
|
|
173
|
+
const validated = tool.validate(args ?? {});
|
|
174
|
+
switch (name) {
|
|
175
|
+
case 'thread-start':
|
|
176
|
+
return this.handleThreadStart(validated as ThreadStartInput);
|
|
177
|
+
case 'thread-resume':
|
|
178
|
+
return this.handleThreadResume(validated as ThreadResumeInput);
|
|
179
|
+
case 'thread-read':
|
|
180
|
+
return this.handleThreadRead(validated as ThreadReadInput);
|
|
181
|
+
case 'thread-list':
|
|
182
|
+
return this.handleThreadList(validated as ThreadListInput);
|
|
183
|
+
case 'turn-start':
|
|
184
|
+
return this.handleTurnStart(validated as TurnStartInput);
|
|
185
|
+
case 'turn-steer':
|
|
186
|
+
return this.handleTurnSteer(validated as TurnSteerInput);
|
|
187
|
+
case 'turn-interrupt':
|
|
188
|
+
return this.handleTurnInterrupt(validated as TurnInterruptInput);
|
|
189
|
+
case 'model-list':
|
|
190
|
+
return JSON.stringify({
|
|
191
|
+
data: await this.runtime.listModels(false),
|
|
192
|
+
}, null, 2);
|
|
193
|
+
case 'account-read':
|
|
194
|
+
return JSON.stringify(await this.runtime.request('account/read', {}), null, 2);
|
|
195
|
+
case 'account-rate-limits-read':
|
|
196
|
+
return JSON.stringify(await this.runtime.request('account/rateLimits/read', {}), null, 2);
|
|
197
|
+
case 'skills-list':
|
|
198
|
+
return JSON.stringify(await this.runtime.request('skills/list', {}), null, 2);
|
|
199
|
+
case 'app-list':
|
|
200
|
+
return JSON.stringify(await this.runtime.request('app/list', {}), null, 2);
|
|
201
|
+
case 'request-list':
|
|
202
|
+
return JSON.stringify({
|
|
203
|
+
requests: this.runtime.getPendingServerRequests(
|
|
204
|
+
Boolean((validated as { include_resolved?: boolean }).include_resolved),
|
|
205
|
+
),
|
|
206
|
+
}, null, 2);
|
|
207
|
+
case 'request-read':
|
|
208
|
+
return JSON.stringify({
|
|
209
|
+
request: this.runtime.getPendingServerRequest(
|
|
210
|
+
(validated as { request_id: string | number }).request_id,
|
|
211
|
+
) ?? null,
|
|
212
|
+
}, null, 2);
|
|
213
|
+
case 'request-respond':
|
|
214
|
+
return this.handleRequestRespond(validated as RequestRespondInput);
|
|
215
|
+
case 'wait':
|
|
216
|
+
return this.handleWait(validated as WaitInput);
|
|
217
|
+
default:
|
|
218
|
+
throw new Error(`Unhandled tool: ${name}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private async handleThreadStart(input: ThreadStartInput): Promise<string> {
|
|
223
|
+
const built = await this.runtime.buildThreadStartParams({
|
|
224
|
+
model: input.model,
|
|
225
|
+
cwd: input.cwd,
|
|
226
|
+
developerInstructions: input.developer_instructions,
|
|
227
|
+
});
|
|
228
|
+
const response = await this.runtime.request('thread/start', built.params);
|
|
229
|
+
const threadId = (response as { thread?: { id?: string } }).thread?.id;
|
|
230
|
+
if (threadId) {
|
|
231
|
+
this.runtime.rememberThreadId(threadId);
|
|
232
|
+
}
|
|
233
|
+
return JSON.stringify({
|
|
234
|
+
method: 'thread/start',
|
|
235
|
+
remapped_from: built.remappedFrom,
|
|
236
|
+
result: response,
|
|
237
|
+
}, null, 2);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private async handleThreadResume(input: ThreadResumeInput): Promise<string> {
|
|
241
|
+
const built = await this.runtime.buildThreadResumeParams({
|
|
242
|
+
threadId: input.thread_id,
|
|
243
|
+
model: input.model,
|
|
244
|
+
cwd: input.cwd,
|
|
245
|
+
developerInstructions: input.developer_instructions,
|
|
246
|
+
});
|
|
247
|
+
const response = await this.runtime.request('thread/resume', built.params);
|
|
248
|
+
this.runtime.rememberThreadId(input.thread_id);
|
|
249
|
+
return JSON.stringify({
|
|
250
|
+
method: 'thread/resume',
|
|
251
|
+
remapped_from: built.remappedFrom,
|
|
252
|
+
result: response,
|
|
253
|
+
}, null, 2);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private async handleThreadRead(input: ThreadReadInput): Promise<string> {
|
|
257
|
+
const response = await this.runtime.request('thread/read', {
|
|
258
|
+
threadId: input.thread_id,
|
|
259
|
+
includeTurns: input.include_turns ?? true,
|
|
260
|
+
});
|
|
261
|
+
this.runtime.rememberThreadId(input.thread_id);
|
|
262
|
+
return JSON.stringify(response, null, 2);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private async handleThreadList(input: ThreadListInput): Promise<string> {
|
|
266
|
+
const response = await this.runtime.request('thread/list', {
|
|
267
|
+
limit: input.limit,
|
|
268
|
+
cursor: input.cursor ?? null,
|
|
269
|
+
}) as {
|
|
270
|
+
data?: Array<{ id?: string }>;
|
|
271
|
+
};
|
|
272
|
+
for (const row of response.data ?? []) {
|
|
273
|
+
if (typeof row.id === 'string') {
|
|
274
|
+
this.runtime.rememberThreadId(row.id);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return JSON.stringify(response, null, 2);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private async handleTurnStart(input: TurnStartInput): Promise<string> {
|
|
281
|
+
const built = await this.runtime.buildTurnStartParams({
|
|
282
|
+
threadId: input.thread_id,
|
|
283
|
+
userInput: input.user_input,
|
|
284
|
+
model: input.model,
|
|
285
|
+
});
|
|
286
|
+
await this.runtime.ensureThreadLoaded(input.thread_id, input.model);
|
|
287
|
+
const bridged = await this.runtime.requestWithBridge('turn/start', built.params, {
|
|
288
|
+
threadId: input.thread_id,
|
|
289
|
+
});
|
|
290
|
+
return JSON.stringify({
|
|
291
|
+
method: 'turn/start',
|
|
292
|
+
remapped_from: built.remappedFrom,
|
|
293
|
+
...bridged,
|
|
294
|
+
}, null, 2);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private async handleTurnSteer(input: TurnSteerInput): Promise<string> {
|
|
298
|
+
const params = this.runtime.buildTurnSteerParams({
|
|
299
|
+
threadId: input.thread_id,
|
|
300
|
+
expectedTurnId: input.expected_turn_id,
|
|
301
|
+
userInput: input.user_input,
|
|
302
|
+
});
|
|
303
|
+
const bridged = await this.runtime.requestWithBridge('turn/steer', params, {
|
|
304
|
+
threadId: input.thread_id,
|
|
305
|
+
});
|
|
306
|
+
return JSON.stringify({
|
|
307
|
+
method: 'turn/steer',
|
|
308
|
+
...bridged,
|
|
309
|
+
}, null, 2);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private async handleTurnInterrupt(input: TurnInterruptInput): Promise<string> {
|
|
313
|
+
const response = await this.runtime.request('turn/interrupt', {
|
|
314
|
+
threadId: input.thread_id,
|
|
315
|
+
turnId: input.turn_id,
|
|
316
|
+
});
|
|
317
|
+
return JSON.stringify(response, null, 2);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private async handleRequestRespond(input: RequestRespondInput): Promise<string> {
|
|
321
|
+
const pending = this.runtime.getPendingServerRequest(input.request_id);
|
|
322
|
+
if (!pending) {
|
|
323
|
+
throw new Error(`Pending server request not found: ${String(input.request_id)}`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const payload = this.buildServerRequestPayload(pending.method, input);
|
|
327
|
+
await this.runtime.respondToServerRequest(input.request_id, payload);
|
|
328
|
+
return JSON.stringify({
|
|
329
|
+
request_id: input.request_id,
|
|
330
|
+
method: pending.method,
|
|
331
|
+
payload,
|
|
332
|
+
status: 'responded',
|
|
333
|
+
}, null, 2);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private async handleWait(input: WaitInput): Promise<string> {
|
|
337
|
+
const timeoutMs = input.timeout_ms ?? REQUEST_TIMEOUT_MS;
|
|
338
|
+
const pollIntervalMs = input.poll_interval_ms ?? OPERATION_POLL_INTERVAL_MS;
|
|
339
|
+
|
|
340
|
+
if (input.operation_id) {
|
|
341
|
+
const operation = await this.runtime.waitForOperation(input.operation_id, timeoutMs, pollIntervalMs);
|
|
342
|
+
return JSON.stringify(operation, null, 2);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (input.thread_id) {
|
|
346
|
+
const start = Date.now();
|
|
347
|
+
while (Date.now() - start <= timeoutMs) {
|
|
348
|
+
const response = await this.runtime.request('thread/read', {
|
|
349
|
+
threadId: input.thread_id,
|
|
350
|
+
includeTurns: false,
|
|
351
|
+
}) as {
|
|
352
|
+
thread?: {
|
|
353
|
+
status?: { type?: string };
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
const statusType = response.thread?.status?.type;
|
|
357
|
+
if (statusType !== 'active') {
|
|
358
|
+
return JSON.stringify({
|
|
359
|
+
thread_id: input.thread_id,
|
|
360
|
+
status: statusType ?? 'unknown',
|
|
361
|
+
thread: response.thread ?? null,
|
|
362
|
+
}, null, 2);
|
|
363
|
+
}
|
|
364
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
365
|
+
}
|
|
366
|
+
throw new Error(`Timed out waiting for thread ${input.thread_id}`);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return JSON.stringify({
|
|
370
|
+
requests: this.runtime.getPendingServerRequests(false),
|
|
371
|
+
operations: [],
|
|
372
|
+
}, null, 2);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private buildServerRequestPayload(method: string, input: RequestRespondInput): unknown {
|
|
376
|
+
if (input.payload) {
|
|
377
|
+
return input.payload;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
switch (method) {
|
|
381
|
+
case 'item/commandExecution/requestApproval':
|
|
382
|
+
case 'item/fileChange/requestApproval':
|
|
383
|
+
return {
|
|
384
|
+
decision: input.decision ?? 'accept',
|
|
385
|
+
};
|
|
386
|
+
case 'item/tool/requestUserInput':
|
|
387
|
+
return {
|
|
388
|
+
answers: input.answers ?? {},
|
|
389
|
+
};
|
|
390
|
+
case 'mcpServer/elicitation/request':
|
|
391
|
+
return {
|
|
392
|
+
action: input.action ?? 'accept',
|
|
393
|
+
content: input.content ?? null,
|
|
394
|
+
_meta: input.meta ?? null,
|
|
395
|
+
};
|
|
396
|
+
case 'item/permissions/requestApproval':
|
|
397
|
+
return {
|
|
398
|
+
permissions: input.permissions ?? {},
|
|
399
|
+
scope: input.scope ?? 'session',
|
|
400
|
+
};
|
|
401
|
+
case 'item/tool/call':
|
|
402
|
+
return {
|
|
403
|
+
contentItems: [],
|
|
404
|
+
success: true,
|
|
405
|
+
};
|
|
406
|
+
case 'applyPatchApproval':
|
|
407
|
+
case 'execCommandApproval':
|
|
408
|
+
return {
|
|
409
|
+
decision: input.decision ?? 'approved',
|
|
410
|
+
};
|
|
411
|
+
default:
|
|
412
|
+
throw new Error(
|
|
413
|
+
`No default response payload for request method ${method}. Provide payload explicitly.`,
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const APP_NAME = 'mcp-codex-worker';
|
|
2
|
+
export const APP_TITLE = 'MCP Codex Worker';
|
|
3
|
+
export const REQUEST_TIMEOUT_MS = 120_000;
|
|
4
|
+
export const OPERATION_BRIDGE_TIMEOUT_MS = 2_000;
|
|
5
|
+
export const OPERATION_POLL_INTERVAL_MS = 250;
|
|
6
|
+
|
|
7
|
+
export const CODEX_APP_SERVER_COMMAND_ENV = 'CODEX_APP_SERVER_COMMAND';
|
|
8
|
+
export const CODEX_APP_SERVER_ARGS_ENV = 'CODEX_APP_SERVER_ARGS';
|
|
9
|
+
export const CODEX_HOME_ENV = 'CODEX_HOME';
|
|
10
|
+
export const CODEX_HOME_DIRS_ENV = 'CODEX_HOME_DIRS';
|
|
11
|
+
export const CODEX_ENABLE_FLEET_ENV = 'CODEX_ENABLE_FLEET';
|
|
12
|
+
|
|
13
|
+
export const PROFILE_COOLDOWN_MS = 60_000;
|
|
14
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
|
|
5
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
+
import {
|
|
8
|
+
CallToolRequestSchema,
|
|
9
|
+
ListResourcesRequestSchema,
|
|
10
|
+
ListToolsRequestSchema,
|
|
11
|
+
ReadResourceRequestSchema,
|
|
12
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
13
|
+
|
|
14
|
+
import { CodexWorkerApp } from './app.js';
|
|
15
|
+
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const pkg = require('../package.json') as { version: string };
|
|
18
|
+
|
|
19
|
+
const app = new CodexWorkerApp();
|
|
20
|
+
const server = new Server(
|
|
21
|
+
{ name: 'mcp-codex-worker', version: pkg.version },
|
|
22
|
+
{
|
|
23
|
+
capabilities: {
|
|
24
|
+
tools: {},
|
|
25
|
+
resources: {},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
31
|
+
tools: (await app.listTools()).map((tool) => ({
|
|
32
|
+
name: tool.name,
|
|
33
|
+
description: tool.description,
|
|
34
|
+
inputSchema: tool.inputSchema,
|
|
35
|
+
})),
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
39
|
+
try {
|
|
40
|
+
const text = await app.callTool(request.params.name, request.params.arguments ?? {});
|
|
41
|
+
return { content: [{ type: 'text', text }] };
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }],
|
|
45
|
+
isError: true as const,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
51
|
+
resources: app.listResources(),
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
55
|
+
const resource = await app.readResource(request.params.uri);
|
|
56
|
+
return {
|
|
57
|
+
contents: [{
|
|
58
|
+
uri: request.params.uri,
|
|
59
|
+
mimeType: resource.mimeType,
|
|
60
|
+
text: resource.text,
|
|
61
|
+
}],
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
async function main(): Promise<void> {
|
|
66
|
+
await app.initialize();
|
|
67
|
+
const transport = new StdioServerTransport();
|
|
68
|
+
await server.connect(transport);
|
|
69
|
+
process.stdin.resume();
|
|
70
|
+
|
|
71
|
+
const shutdown = async () => {
|
|
72
|
+
await app.shutdown().catch(() => {});
|
|
73
|
+
process.exit(0);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
process.on('SIGINT', () => void shutdown());
|
|
77
|
+
process.on('SIGTERM', () => void shutdown());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main().catch((error) => {
|
|
81
|
+
console.error(error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
|