Skip to content

Commit b05364e

Browse files
committed
Fix codegen and Rust SQLite params
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 33b674a commit b05364e

9 files changed

Lines changed: 43 additions & 19 deletions

File tree

go/rpc/zrpc.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/e2e/test_rpc_mcp_config_e2e.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
MCPConfigUpdateRequest,
2020
MCPServerConfig,
2121
MCPServerConfigHTTPOauthGrantType,
22-
MCPServerConfigType,
22+
MCPServerConfigHTTPType,
2323
)
2424

2525
from .testharness import E2ETestContext
@@ -71,7 +71,7 @@ async def test_should_round_trip_http_mcp_oauth_config_rpc(self, ctx: E2ETestCon
7171

7272
server_name = f"sdk-http-oauth-{uuid.uuid4().hex}"
7373
config = MCPServerConfig(
74-
type=MCPServerConfigType.HTTP,
74+
type=MCPServerConfigHTTPType.HTTP,
7575
url="https://example.com/mcp",
7676
headers={"Authorization": "Bearer token"},
7777
oauth_client_id="client-id",
@@ -81,7 +81,7 @@ async def test_should_round_trip_http_mcp_oauth_config_rpc(self, ctx: E2ETestCon
8181
timeout=3000,
8282
)
8383
updated_config = MCPServerConfig(
84-
type=MCPServerConfigType.HTTP,
84+
type=MCPServerConfigHTTPType.HTTP,
8585
url="https://example.com/updated-mcp",
8686
oauth_client_id="updated-client-id",
8787
oauth_public_client=True,
@@ -96,7 +96,7 @@ async def test_should_round_trip_http_mcp_oauth_config_rpc(self, ctx: E2ETestCon
9696
)
9797
after_add = await ctx.client.rpc.mcp.config.list()
9898
added = _server_config(after_add.servers, server_name)
99-
assert added.type == MCPServerConfigType.HTTP
99+
assert added.type == MCPServerConfigHTTPType.HTTP
100100
assert added.url == "https://example.com/mcp"
101101
assert added.headers is not None
102102
assert added.headers["Authorization"] == "Bearer token"

rust/src/generated/api_types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use serde::{Deserialize, Serialize};
99
use super::session_events::{
1010
McpServerSource, McpServerStatus, ReasoningSummary, SessionMode, SkillSource,
1111
};
12-
1312
use crate::types::{RequestId, SessionId};
1413

1514
/// JSON-RPC method name constants.
@@ -969,7 +968,7 @@ pub struct McpServer {
969968
pub struct McpServerConfigHttpAuth {
970969
/// Fixed port for the OAuth redirect callback server.
971970
#[serde(skip_serializing_if = "Option::is_none")]
972-
pub redirect_port: Option<i64>,
971+
pub redirect_port: Option<i32>,
973972
}
974973

975974
/// Remote MCP server configuration accessed over HTTP or SSE.

rust/src/session_fs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use crate::generated::api_types::{
4848
SessionFsError, SessionFsErrorCode, SessionFsReaddirWithTypesEntry,
4949
SessionFsReaddirWithTypesEntryType, SessionFsSetProviderConventions, SessionFsStatResult,
5050
};
51-
5251
pub use crate::generated::api_types::{SessionFsSqliteQueryResult, SessionFsSqliteQueryType};
5352

5453
/// Configuration for a custom session filesystem provider.
@@ -354,7 +353,7 @@ pub trait SessionFsProvider: Send + Sync + 'static {
354353
session_id: &str,
355354
query: &str,
356355
query_type: SessionFsSqliteQueryType,
357-
params: &HashMap<String, serde_json::Value>,
356+
params: Option<&HashMap<String, serde_json::Value>>,
358357
) -> Result<SessionFsSqliteQueryResult, FsError> {
359358
let _ = (session_id, query, query_type, params);
360359
Err(FsError::Other("sqlite_query not supported".to_string()))

rust/src/session_fs_dispatch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,13 @@ pub(crate) async fn sqlite_query(
316316
}
317317
};
318318
let id = request.id;
319+
let sqlite_params = (!params.params.is_empty()).then_some(&params.params);
319320
let result = match provider
320321
.sqlite_query(
321322
params.session_id.as_ref(),
322323
&params.query,
323324
params.query_type,
324-
&params.params,
325+
sqlite_params,
325326
)
326327
.await
327328
{

rust/tests/e2e/session_fs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,14 @@ async fn should_map_all_sessionfs_handler_operations() {
206206
provider.stat("/workspace/nested/missing.txt").await,
207207
Err(FsError::NotFound(_))
208208
));
209+
let sqlite_params =
210+
std::collections::HashMap::from([("answer".to_string(), serde_json::Value::from(42))]);
209211
let sqlite_result = provider
210212
.sqlite_query(
211213
"handler-session",
212214
"select :answer as answer",
213215
SessionFsSqliteQueryType::Query,
214-
&std::collections::HashMap::from([("answer".to_string(), serde_json::Value::from(42))]),
216+
Some(&sqlite_params),
215217
)
216218
.await
217219
.expect("sqlite query");
@@ -626,7 +628,7 @@ impl SessionFsProvider for TestSessionFsProvider {
626628
session_id: &str,
627629
query: &str,
628630
query_type: SessionFsSqliteQueryType,
629-
params: &std::collections::HashMap<String, serde_json::Value>,
631+
params: Option<&std::collections::HashMap<String, serde_json::Value>>,
630632
) -> Result<SessionFsSqliteQueryResult, FsError> {
631633
let mut row = std::collections::HashMap::new();
632634
row.insert("sessionId".to_string(), session_id.to_string().into());
@@ -644,7 +646,7 @@ impl SessionFsProvider for TestSessionFsProvider {
644646
row.insert(
645647
"answer".to_string(),
646648
params
647-
.get("answer")
649+
.and_then(|params| params.get("answer"))
648650
.cloned()
649651
.unwrap_or(serde_json::Value::Null),
650652
);

rust/tests/session_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ impl SessionFsProvider for RecordingFsProvider {
29902990
session_id: &str,
29912991
query: &str,
29922992
query_type: SessionFsSqliteQueryType,
2993-
params: &std::collections::HashMap<String, serde_json::Value>,
2993+
params: Option<&std::collections::HashMap<String, serde_json::Value>>,
29942994
) -> Result<SessionFsSqliteQueryResult, FsError> {
29952995
let mut row = std::collections::HashMap::new();
29962996
row.insert(
@@ -3016,7 +3016,7 @@ impl SessionFsProvider for RecordingFsProvider {
30163016
row.insert(
30173017
"answer".to_string(),
30183018
params
3019-
.get("answer")
3019+
.and_then(|params| params.get("answer"))
30203020
.cloned()
30213021
.unwrap_or(serde_json::Value::Null),
30223022
);
@@ -3221,7 +3221,7 @@ async fn session_fs_maps_sqlite_errors_to_results() {
32213221
_session_id: &str,
32223222
_query: &str,
32233223
_query_type: SessionFsSqliteQueryType,
3224-
_params: &std::collections::HashMap<String, serde_json::Value>,
3224+
_params: Option<&std::collections::HashMap<String, serde_json::Value>>,
32253225
) -> Result<SessionFsSqliteQueryResult, FsError> {
32263226
Err(FsError::Other("sqlite unavailable".to_string()))
32273227
}

scripts/codegen/go.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ const goInitialisms = new Set(["id", "ui", "uri", "url", "api", "http", "https",
6666
const goCommentTextWrapLength = 90;
6767
const wrapGoCommentText = wordwrap(goCommentTextWrapLength);
6868

69+
function goIntegerType(schema: JSONSchema7): "int32" | "int64" {
70+
const { minimum, maximum } = schema;
71+
return Number.isInteger(minimum) &&
72+
Number.isInteger(maximum) &&
73+
minimum >= -2147483648 &&
74+
maximum <= 2147483647
75+
? "int32"
76+
: "int64";
77+
}
78+
6979
function toPascalCase(s: string): string {
7080
return s
7181
.split(/[^A-Za-z0-9]+/)
@@ -852,7 +862,10 @@ function resolveGoPropertyType(
852862
return isRequired ? "string" : "*string";
853863
}
854864
if (type === "number") return isRequired ? "float64" : "*float64";
855-
if (type === "integer") return isRequired ? "int64" : "*int64";
865+
if (type === "integer") {
866+
const integerType = goIntegerType(propSchema);
867+
return isRequired ? integerType : `*${integerType}`;
868+
}
856869
if (type === "boolean") return isRequired ? "bool" : "*bool";
857870

858871
// Array type
@@ -2294,7 +2307,7 @@ function goPrimitiveSchemaGoType(schema: JSONSchema7, ctx: GoCodegenCtx): string
22942307
const resolved = resolveSchema(schema, ctx.definitions) ?? schema;
22952308
switch (resolved.type) {
22962309
case "boolean": return "bool";
2297-
case "integer": return "int64";
2310+
case "integer": return goIntegerType(resolved);
22982311
case "number": return "float64";
22992312
case "string": return "string";
23002313
default: return undefined;

scripts/codegen/rust.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ const STRING_NEWTYPE_OVERRIDES: Record<string, string> = {
7474
requestId: "RequestId",
7575
};
7676

77+
function rustIntegerType(schema: JSONSchema7): "i32" | "i64" {
78+
const { minimum, maximum } = schema;
79+
return Number.isInteger(minimum) &&
80+
Number.isInteger(maximum) &&
81+
minimum >= -2147483648 &&
82+
maximum <= 2147483647
83+
? "i32"
84+
: "i64";
85+
}
86+
7787
// ── Naming helpers ──────────────────────────────────────────────────────────
7888

7989
function toPascalCase(s: string): string {
@@ -663,7 +673,7 @@ function resolveRustType(
663673
return wrapOption("String", isRequired);
664674
}
665675
if (schemaType === "number") return wrapOption("f64", isRequired);
666-
if (schemaType === "integer") return wrapOption("i64", isRequired);
676+
if (schemaType === "integer") return wrapOption(rustIntegerType(propSchema), isRequired);
667677
if (schemaType === "boolean") return wrapOption("bool", isRequired);
668678

669679
// Array

0 commit comments

Comments
 (0)