Skip to content

Add sproc command for stored procedures#124

Open
mkrueger wants to merge 8 commits into
mainfrom
dev/mkrueger/sproc
Open

Add sproc command for stored procedures#124
mkrueger wants to merge 8 commits into
mainfrom
dev/mkrueger/sproc

Conversation

@mkrueger

Copy link
Copy Markdown
Contributor

Summary

Adds a sproc command for working with Azure Cosmos DB stored procedures from the shell, with an interactive editor workflow and clean, human-friendly output.

Changes

  • New sproc command with subcommands: list, show, create, exec, edit, delete (MCP-restricted).
  • sproc list renders a human-readable table (Id / Last Modified / Size) for interactive sessions while still returning structured JSON for MCP consumers.
  • sproc create opens an external editor, then shows a preview and a confirmation prompt before creating the stored procedure.
  • sproc edit edits an existing stored procedure body and fails with a not-found error if it does not exist (use create to add a new one).
  • Quick-exit editor handling: if the editor returns immediately, the shell waits for the user to finish editing and press Enter.
  • Status messages (create/replace/delete/edit) now set IsPrinted so the JSON echo is hidden in the interactive shell and only surfaced over MCP.
  • Removed the redundant --editor option from the theme and sproc commands.

Validation

  • dotnet build CosmosDBShell.Tests/CosmosDBShell.Tests.csproj — succeeds.
  • Sproc, localization audit, and help verification tests pass (32 passed / 0 failed).

mkrueger added 5 commits June 10, 2026 12:53
The editor is now always resolved from $VISUAL, then $EDITOR, then a
platform default, matching the �dit command. Drops the --editor option
and its localized help/docs for 	heme edit and sproc edit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new sproc command to the Cosmos DB Shell for managing stored procedures (list/show/create/exec/edit/delete), including an external-editor workflow for authoring and editing bodies, updated help/localization, MCP restrictions documentation, and test coverage for MCP tooling metadata.

Changes:

  • Introduces sproc command implementation plus docs/localization entries and changelog note.
  • Removes the redundant --editor option from theme (and updates docs/localization accordingly).
  • Adds/extends tests to validate MCP restriction annotations and sproc helper behaviors.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Mentions the new sproc command in the feature list.
docs/mcp.md Documents that sproc operations are restricted from MCP.
docs/commands.md Updates theme usage and adds full sproc command documentation.
CosmosDBShell/lang/en.ftl Adds sproc localized strings and removes the theme editor option string.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ThemeCommand.cs Removes --editor option handling and always resolves editor from environment defaults.
CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs Implements the new stored procedure command and editor workflow.
CosmosDBShell.Tests/ToolOperationsTests.cs Adds a test asserting sproc is MCP-restricted and annotated as destructive/open-world.
CosmosDBShell.Tests/CommandTests/SprocCommandTests.cs Adds unit tests for sproc helper methods (normalize/param parsing/PK parsing/template seed).
CHANGELOG.md Adds an Unreleased entry describing the new sproc command.

Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs
Comment thread CosmosDBShell.Tests/CommandTests/SprocCommandTests.cs
mkrueger added 2 commits June 10, 2026 14:13
…anches

Adds 'sproc exists <name>' which returns a ShellBool so it can be used
directly in if/while conditions. Also fixes CommandStatement.RunAsync so it
resets IsPrinted at the start of each statement; previously a prior command
that set IsPrinted (such as a condition command in an if) leaked the flag
and suppressed the branch command's output in PrintState.
Copilot AI review requested due to automatic review settings June 10, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Comments suppressed due to low confidence (1)

CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/ThemeCommand.cs:660

  • ThemeCommand no longer supports --editor, but when no editor is found it still uses the theme-specific message key whose text says "or pass --editor=". This produces an incorrect user-facing error now that the option is removed.
        var editor = ExternalEditor.Resolve(null);
        if (editor is null)
        {
            var message = MessageService.GetString("command-theme-edit-no-editor");
            AnsiConsole.MarkupLine(Theme.FormatError(message));
            return new ErrorCommandState(new CommandException("theme", message));

Comment thread README.md Outdated
Comment thread CosmosDBShell/lang/en.ftl Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/SprocCommand.cs
Comment thread docs/commands.md
Comment thread docs/commands.md Outdated
- Reject object-shaped/malformed --partition-key instead of silent string fallback (new command-sproc-error-invalid_pk)
- List exists/edit subcommands in the MCP annotation description
- Drop misleading 'MCP server' mention from the create comment
- Add exists to sproc help description strings
- Fix obsolete '--editor' hint in command-theme-edit-no-editor
- Add exists to the sproc feature list in README
- Document sproc list JSON metadata and that sproc is MCP-restricted in docs
- Add unit test for object-shaped partition key rejection
@mkrueger mkrueger requested review from sajeetharan and sevoku June 15, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants