Compare commits

...

1 Commits

Author SHA1 Message Date
Ruslan Nigmatullin
b7280fa475 app-server: Return codex home in initialize response 2026-03-24 15:08:20 -07:00
7 changed files with 24 additions and 1 deletions

View File

@@ -2257,6 +2257,10 @@
"InitializeResponse": {
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"codexHome": {
"description": "Absolute path to the server's Codex home directory.",
"type": "string"
},
"platformFamily": {
"description": "Platform family for the running app-server target, for example `\"unix\"` or `\"windows\"`.",
"type": "string"
@@ -2270,6 +2274,7 @@
}
},
"required": [
"codexHome",
"platformFamily",
"platformOs",
"userAgent"

View File

@@ -1,6 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"codexHome": {
"description": "Absolute path to the server's Codex home directory.",
"type": "string"
},
"platformFamily": {
"description": "Platform family for the running app-server target, for example `\"unix\"` or `\"windows\"`.",
"type": "string"
@@ -14,6 +18,7 @@
}
},
"required": [
"codexHome",
"platformFamily",
"platformOs",
"userAgent"

View File

@@ -3,6 +3,10 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type InitializeResponse = { userAgent: string,
/**
* Absolute path to the server's Codex home directory.
*/
codexHome: string,
/**
* Platform family for the running app-server target, for example
* `"unix"` or `"windows"`.

View File

@@ -56,6 +56,8 @@ pub struct InitializeCapabilities {
#[serde(rename_all = "camelCase")]
pub struct InitializeResponse {
pub user_agent: String,
/// Absolute path to the server's Codex home directory.
pub codex_home: PathBuf,
/// Platform family for the running app-server target, for example
/// `"unix"` or `"windows"`.
pub platform_family: String,

View File

@@ -75,7 +75,7 @@ Use the thread APIs to create, list, or archive conversations. Drive a conversat
## Initialization
Clients must send a single `initialize` request per transport connection before invoking any other method on that connection, then acknowledge with an `initialized` notification. The server returns the user agent string it will present to upstream services plus `platformFamily` and `platformOs` strings describing the app-server runtime target; subsequent requests issued before initialization receive a `"Not initialized"` error, and repeated `initialize` calls on the same connection receive an `"Already initialized"` error.
Clients must send a single `initialize` request per transport connection before invoking any other method on that connection, then acknowledge with an `initialized` notification. The server returns the user agent string it will present to upstream services, `codexHome` for the server's Codex home directory, and `platformFamily` and `platformOs` strings describing the app-server runtime target; subsequent requests issued before initialization receive a `"Not initialized"` error, and repeated `initialize` calls on the same connection receive an `"Already initialized"` error.
`initialize.params.capabilities` also supports per-connection notification opt-out via `optOutNotificationMethods`, which is a list of exact method names to suppress for that connection. Matching is exact (no wildcards/prefixes). Unknown method names are accepted and ignored.

View File

@@ -581,6 +581,7 @@ impl MessageProcessor {
let user_agent = get_codex_user_agent();
let response = InitializeResponse {
user_agent,
codex_home: self.config.codex_home.clone(),
platform_family: std::env::consts::FAMILY.to_string(),
platform_os: std::env::consts::OS.to_string(),
};

View File

@@ -30,6 +30,7 @@ async fn initialize_uses_client_info_name_as_originator() -> Result<()> {
let responses = Vec::new();
let server = create_mock_responses_server_sequence_unchecked(responses).await;
let codex_home = TempDir::new()?;
let expected_codex_home = codex_home.path().canonicalize()?;
create_config_toml(codex_home.path(), &server.uri(), "never")?;
let mut mcp = McpProcess::new(codex_home.path()).await?;
@@ -48,11 +49,13 @@ async fn initialize_uses_client_info_name_as_originator() -> Result<()> {
};
let InitializeResponse {
user_agent,
codex_home: response_codex_home,
platform_family,
platform_os,
} = to_response::<InitializeResponse>(response)?;
assert!(user_agent.starts_with("codex_vscode/"));
assert_eq!(response_codex_home, expected_codex_home);
assert_eq!(platform_family, std::env::consts::FAMILY);
assert_eq!(platform_os, std::env::consts::OS);
Ok(())
@@ -63,6 +66,7 @@ async fn initialize_respects_originator_override_env_var() -> Result<()> {
let responses = Vec::new();
let server = create_mock_responses_server_sequence_unchecked(responses).await;
let codex_home = TempDir::new()?;
let expected_codex_home = codex_home.path().canonicalize()?;
create_config_toml(codex_home.path(), &server.uri(), "never")?;
let mut mcp = McpProcess::new_with_env(
codex_home.path(),
@@ -88,11 +92,13 @@ async fn initialize_respects_originator_override_env_var() -> Result<()> {
};
let InitializeResponse {
user_agent,
codex_home: response_codex_home,
platform_family,
platform_os,
} = to_response::<InitializeResponse>(response)?;
assert!(user_agent.starts_with("codex_originator_via_env_var/"));
assert_eq!(response_codex_home, expected_codex_home);
assert_eq!(platform_family, std::env::consts::FAMILY);
assert_eq!(platform_os, std::env::consts::OS);
Ok(())