Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ ignore = [
"TRY003", # Raise with inline message strings

# Backwards-compatibility suppressions for existing code
"A001", # Variable shadows built-in
"A002", # Argument shadows built-in
"A004", # Import shadows built-in
"FBT001", # Boolean positional arg
Expand Down
33 changes: 15 additions & 18 deletions src/seclab_taskflow_agent/mcp_servers/codeql/jsonrpyc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def request(
# add the id when given
if id is not None:
# encode string ids
if isinstance(id, str):
id = json.dumps(id)
req += f',"id":{id}'
encoded_id = json.dumps(id) if isinstance(id, str) else id
req += f',"id":{encoded_id}'
Comment on lines +151 to +152
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoded_id is only JSON-encoded for string IDs, which means a boolean ID (allowed by check_id because bool is a subclass of int) would be rendered as True/False in the JSON output, producing invalid JSON. Consider encoding IDs with json.dumps(id) unconditionally here (or tightening check_id to reject bool) so the emitted JSON is always valid.

This issue also appears in the following locations of the same file:

  • line 184
  • line 234

See below for a potential fix:

            # always JSON-encode the id to ensure valid JSON (e.g. for booleans)
            encoded_id = json.dumps(id)

Copilot uses AI. Check for mistakes.

# add parameters when given
if params is not None:
Expand Down Expand Up @@ -182,12 +181,11 @@ def response(cls, id: str | int | None, result: Any, /) -> str:
raise RPCInvalidRequest(str(e))

# encode string ids
if isinstance(id, str):
id = json.dumps(id)
encoded_id = json.dumps(id) if isinstance(id, str) else id

# build the response string
try:
res = f'{{"jsonrpc":"2.0","id":{id},"result":{json.dumps(result)}}}'
res = f'{{"jsonrpc":"2.0","id":{encoded_id},"result":{json.dumps(result)}}}'
except Exception as e:
raise RPCParseError(str(e))

Expand Down Expand Up @@ -233,11 +231,10 @@ def error(
err_data += "}"

# encode string ids
if isinstance(id, str):
id = json.dumps(id)
encoded_id = json.dumps(id) if isinstance(id, str) else id

# start building the error string
err = f'{{"jsonrpc":"2.0","id":{id},"error":{err_data}}}'
err = f'{{"jsonrpc":"2.0","id":{encoded_id},"error":{err_data}}}'

return err

Expand Down Expand Up @@ -426,32 +423,32 @@ def call(
is_notification = callback is None and block <= 0

# create a new id for requests expecting a response
id = -1
req_id = -1
if not is_notification:
self._i += 1
id = self._i
req_id = self._i

# register the callback
if callback is not None:
self._callbacks[id] = callback
self._callbacks[req_id] = callback

# store an empty result for the meantime
if block > 0:
self._results[id] = self.EMPTY_RESULT
self._results[req_id] = self.EMPTY_RESULT

# create the request
params = params if params else {"args": args, "kwargs": kwargs}
req = Spec.request(method, id=id, params=params)
req = Spec.request(method, id=req_id, params=params)
print(f"-> {req}")
msg = f"Content-Length: {len(req)}\r\n\r\n{req}"
self._write(msg)

# blocking return value behavior
if block > 0:
while True:
if self._results[id] != self.EMPTY_RESULT:
result = self._results[id]
del self._results[id]
if self._results[req_id] != self.EMPTY_RESULT:
result = self._results[req_id]
del self._results[req_id]
if isinstance(result, Exception):
raise result
return result
Expand All @@ -462,7 +459,7 @@ def call(
raise TimeoutError("RPC Request timed out")

time.sleep(block)
return id
return req_id

def _handle(self, msg: str) -> None:
"""
Expand Down
Loading