-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat(mcp): expose selected environment preferences #10560
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
juliusmarminge
merged 2 commits into
agents/mcp-thin/preview
from
agents/mcp-thin/preferences
Sep 7, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,79 @@ | ||
| import { OrchestratorMcpFailure, type ServerSettings } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Environment from "../../../environment/ServerEnvironment.ts"; | ||
| import * as ThreadCommandExecutor from "../../../orchestration-v2/ThreadCommandExecutor.ts"; | ||
| import * as Settings from "../../../serverSettings.ts"; | ||
| import { McpInvocationContext } from "../../McpInvocationContext.ts"; | ||
| import { readCaller, readMutationCaller, unavailable } from "../../threadAccess.ts"; | ||
| import { EnvironmentToolkit } from "./tools.ts"; | ||
|
|
||
| export function preferences(settings: ServerSettings) { | ||
| const { | ||
| defaultThreadEnvMode, | ||
| newWorktreesStartFromOrigin, | ||
| enableProviderUpdateChecks, | ||
| backgroundActivity, | ||
| sourceControlWritingStyle, | ||
| } = settings; | ||
| const characters = Array.from(sourceControlWritingStyle.customInstructions); | ||
| return { | ||
| defaultThreadEnvMode, | ||
| newWorktreesStartFromOrigin, | ||
| enableProviderUpdateChecks, | ||
| backgroundActivity: { profile: backgroundActivity.profile }, | ||
| sourceControlWritingStyle: { | ||
| ...sourceControlWritingStyle, | ||
| customInstructions: characters.slice(0, 4000).join(""), | ||
| truncated: characters.length > 4000, | ||
| }, | ||
| }; | ||
| } | ||
| const access = (writable = false) => | ||
| Effect.gen(function* () { | ||
| const context = yield* writable ? readMutationCaller() : readCaller(); | ||
| const environment = yield* Environment.ServerEnvironment; | ||
| const descriptor = yield* environment.getDescriptor; | ||
| if (descriptor.environmentId !== context.scope.environmentId) | ||
| return yield* new OrchestratorMcpFailure({ | ||
| code: "capability_denied", | ||
| message: "This credential belongs to another environment.", | ||
| }); | ||
| return { ...context, descriptor, settings: yield* Settings.ServerSettingsService }; | ||
| }); | ||
| export const EnvironmentHandlersLive = EnvironmentToolkit.toLayer({ | ||
| t3_environment_read: () => | ||
| Effect.gen(function* () { | ||
| const { descriptor, settings } = yield* access(); | ||
| const current = yield* settings.getSettings.pipe(Effect.mapError(unavailable)); | ||
| return { | ||
| environmentId: descriptor.environmentId, | ||
| label: descriptor.label, | ||
| serverVersion: descriptor.serverVersion, | ||
| platform: descriptor.platform, | ||
| preferences: preferences(current), | ||
| }; | ||
| }), | ||
| t3_environment_preferences_update: (patch) => | ||
| Effect.gen(function* () { | ||
| const scope = yield* McpInvocationContext; | ||
| const executor = yield* ThreadCommandExecutor.ThreadCommandExecutor; | ||
| return yield* executor.withLock( | ||
| scope.threadId, | ||
| Effect.gen(function* () { | ||
| const { caller, settings } = yield* access(true); | ||
| if ( | ||
| caller.archivedAt !== null || | ||
| caller.runtimeMode !== "full-access" || | ||
| caller.interactionMode !== "default" | ||
| ) | ||
| return yield* new OrchestratorMcpFailure({ | ||
| code: "capability_denied", | ||
| message: "Preference updates require a live full-access/default thread.", | ||
| }); | ||
| return preferences( | ||
| yield* settings.updateSettings(patch).pipe(Effect.mapError(unavailable)), | ||
| ); | ||
| }), | ||
| ); | ||
| }), | ||
| }); | ||
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,67 @@ | ||
| import { | ||
| BackgroundActivityProfile, | ||
| BackgroundActivityProfileSelection, | ||
| ExecutionEnvironmentDescriptor, | ||
| OrchestratorMcpFailure, | ||
| ServerSettings, | ||
| ServerSettingsPatch, | ||
| } from "@t3tools/contracts"; | ||
| import * as Schema from "effect/Schema"; | ||
| import { Tool, Toolkit } from "effect/unstable/ai"; | ||
| import { ServerEnvironment } from "../../../environment/ServerEnvironment.ts"; | ||
| import { ThreadCommandExecutor } from "../../../orchestration-v2/ThreadCommandExecutor.ts"; | ||
| import { ThreadManagementService } from "../../../orchestration-v2/ThreadManagementService.ts"; | ||
| import { ServerSettingsService } from "../../../serverSettings.ts"; | ||
| import { McpInvocationContext } from "../../McpInvocationContext.ts"; | ||
|
|
||
| export const PreferenceFields = { | ||
| defaultThreadEnvMode: ServerSettings.fields.defaultThreadEnvMode, | ||
| newWorktreesStartFromOrigin: ServerSettings.fields.newWorktreesStartFromOrigin, | ||
| enableProviderUpdateChecks: ServerSettings.fields.enableProviderUpdateChecks, | ||
| backgroundActivity: Schema.Struct({ profile: BackgroundActivityProfileSelection }), | ||
| sourceControlWritingStyle: Schema.Struct({ | ||
| mode: Schema.String, | ||
| followChangeRequestTemplates: Schema.Boolean, | ||
| customInstructions: Schema.String, | ||
| truncated: Schema.Boolean, | ||
| }), | ||
| }; | ||
| const shared = { | ||
| failure: OrchestratorMcpFailure, | ||
| failureMode: "return" as const, | ||
| dependencies: [ | ||
| McpInvocationContext, | ||
| ThreadManagementService, | ||
| ServerEnvironment, | ||
| ServerSettingsService, | ||
| ThreadCommandExecutor, | ||
| ], | ||
| }; | ||
| export const EnvironmentReadTool = Tool.make("t3_environment_read", { | ||
| ...shared, | ||
| description: | ||
| "Read this server's identity and selected environment preferences. Provider/model availability is exposed by orchestrator_capabilities. Writing instructions are limited to 4,000 characters.", | ||
| success: Schema.Struct({ | ||
| environmentId: ExecutionEnvironmentDescriptor.fields.environmentId, | ||
| label: Schema.String, | ||
| serverVersion: Schema.String, | ||
| platform: ExecutionEnvironmentDescriptor.fields.platform, | ||
| preferences: Schema.Struct(PreferenceFields), | ||
| }), | ||
| }) | ||
| .annotate(Tool.Readonly, true) | ||
| .annotate(Tool.Destructive, false); | ||
| export const EnvironmentPreferencesTool = Tool.make("t3_environment_preferences_update", { | ||
| ...shared, | ||
| description: | ||
| "Update selected environment-wide preferences through normal settings persistence and notifications. Requires a live full-access/default calling thread. Omitted fields are preserved; empty customInstructions clears them.", | ||
| parameters: Schema.Struct({ | ||
| defaultThreadEnvMode: ServerSettingsPatch.fields.defaultThreadEnvMode, | ||
| newWorktreesStartFromOrigin: ServerSettingsPatch.fields.newWorktreesStartFromOrigin, | ||
| enableProviderUpdateChecks: ServerSettingsPatch.fields.enableProviderUpdateChecks, | ||
| backgroundActivity: Schema.optionalKey(Schema.Struct({ profile: BackgroundActivityProfile })), | ||
| sourceControlWritingStyle: ServerSettingsPatch.fields.sourceControlWritingStyle, | ||
| }), | ||
| success: Schema.Struct(PreferenceFields), | ||
| }).annotate(Tool.Destructive, true); | ||
| export const EnvironmentToolkit = Toolkit.make(EnvironmentReadTool, EnvironmentPreferencesTool); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.