MCP and OAuth¶
octomate.managers.mcp ¶
Per-user MCP installations: install, enable and authorize them, and pool their clients.
McpUnavailable ¶
Bases: LookupError
The MCP instance or tentacle named is unknown, not the caller's, or not serving.
Source code in octomate/managers/mcp.py
McpClientKey ¶
Bases: NamedTuple
The owner and installation a pooled client is cached under.
Source code in octomate/managers/mcp.py
McpManager ¶
A user's MCP installations: install, enable, authorize and remove them, and pool their clients.
All connections advertise MCP Apps support. Client acquisition and capability negotiation are independent of channel rendering and sandbox configuration.
Source code in octomate/managers/mcp.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
idle_timeout
instance-attribute
¶
idle_timeout: float = (
idle_timeout
if idle_timeout is not None
else McpPoolConfig().idle_timeout
)
httpx_client_factory
instance-attribute
¶
tool_catalogs
instance-attribute
¶
available ¶
install
async
¶
Source code in octomate/managers/mcp.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
list
async
¶
Source code in octomate/managers/mcp.py
summary
async
¶
Source code in octomate/managers/mcp.py
enable
async
¶
Source code in octomate/managers/mcp.py
disable
async
¶
Source code in octomate/managers/mcp.py
uninstall
async
¶
Source code in octomate/managers/mcp.py
authorizable
async
¶
authorizable(
user_id: UUID7,
*,
mcp_id: UUID7 | None = None,
namespace: str | None = None,
) -> OAuthMcp
Source code in octomate/managers/mcp.py
connect
async
¶
connect(
user: User,
mcp_id: UUID7,
*,
profile: UserProfile | None = None,
flow: OAuthFlowKind | None = None,
) -> OAuthStartResult
Source code in octomate/managers/mcp.py
pending_authorization
async
¶
Source code in octomate/managers/mcp.py
cancel_authorization
async
¶
Source code in octomate/managers/mcp.py
confirm
async
¶
confirm(
user: User,
mcp_id: UUID7,
*,
profile: UserProfile | None = None,
) -> McpAuthorizationResult
Source code in octomate/managers/mcp.py
authorization_status
async
¶
Source code in octomate/managers/mcp.py
resolve
async
¶
resolve(
scope: OctomateSession | User,
namespace: str | None = None,
*,
mcp_id: UUID7 | None = None,
) -> tuple[User, Mcp]
Resolve one enabled installation owned by the caller, by namespace or UUID.
Historical invocations supply only their saved UUID. A reused namespace therefore cannot substitute a different installation.
Source code in octomate/managers/mcp.py
catalog
async
¶
catalog(
scope: OctomateSession | User,
namespace: str | None = None,
*,
mcp_id: UUID7 | None = None,
refresh: bool = False,
) -> McpToolCatalog
Read cached discovery, loading it when absent or explicitly refreshed.
Ownership, enabled state, and authorization are checked even on cache hits. The bounded catalog follows its pooled connection's lifetime.
Source code in octomate/managers/mcp.py
call_tool
async
¶
call_tool(
scope: OctomateSession,
namespace: str,
name: str,
arguments: dict[str, JsonValue],
) -> CallToolResult
Execute one upstream call and retain its declared app before publishing.
This boundary sees each call independently, including calls a runtime nests inside a code wrapper. Sessions without thread attribution return the upstream result without producing an artifact or ledger reference. App declarations reuse the connection's latest discovery, loading once when absent. Explicit discovery refreshes them; client eviction clears them.
Source code in octomate/managers/mcp.py
app_resource
async
¶
Read only the saved UI URI from its still-authorized installation UUID.
This performs one resource read, never discovery or tool execution. The response must contain one matching MCP Apps HTML resource, as text or base64-encoded UTF-8. UI metadata is validated before reaching a browser.
Source code in octomate/managers/mcp.py
acquire
async
¶
acquire(
scope: OctomateSession | User,
namespace: str | None = None,
*,
mcp_id: UUID7 | None = None,
) -> AsyncGenerator[Client]
Source code in octomate/managers/mcp.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
expire
async
¶
evict
async
¶
Close a cached client while the caller holds its MCP lock.
Source code in octomate/managers/mcp.py
lifespan
async
¶
octomate.managers.oauth ¶
OAuth connectors and the manager that runs their authorizations for a user, stores the resulting grants, and refreshes them.
NoPendingAuthorization ¶
Bases: ValueError
Nothing of this connector's is waiting on this user to authorize it.
A ValueError still, so the channel handlers reporting a failed connection
keep catching it unchanged; the narrower type is what lets a tool tell the
model to start an authorization rather than reporting the turn as broken.
Source code in octomate/managers/oauth.py
UnusableOAuthOperation ¶
Bases: ValueError
The authorization a browser came back to is gone, spent, or not its own.
One type for every way the round trip can fail to find its operation, because
the browser is told the same thing by all of them — this link is finished, ask
again — and only the log distinguishes them. A ValueError for the same reason
NoPendingAuthorization is one.
Source code in octomate/managers/oauth.py
OAuthConnector
pydantic-model
¶
Bases: BaseModel
One registered integration's injected OAuth composition.
It selects the upstream flow and, for authorization code, the deployment callback
transport. It carries no user identity; OAuthManager supplies the current
channel owner when an authorization starts.
Config:
frozen:Truearbitrary_types_allowed:True
Fields:
-
id(str) -
flows(list[DeviceAuthorizationFlow | AuthorizationCodeFlow]) -
callback_transport(OAuthCallbackTransport | None) -
mcp_url(HttpsUrl | None)
Validators:
Source code in octomate/managers/oauth.py
model_config
class-attribute
instance-attribute
¶
callback_matches_flow
pydantic-validator
¶
Source code in octomate/managers/oauth.py
select_flow ¶
select_flow(
kind: OAuthFlowKind | None = None,
) -> DeviceAuthorizationFlow | AuthorizationCodeFlow
Source code in octomate/managers/oauth.py
resolve_profile
async
¶
An ownerless snapshot verified by this channel's OAuth provider, if supported.
OAuthCallback ¶
Bases: NamedTuple
What a completed authorization-code callback yields: the grant and the account bound to the operation.
Source code in octomate/managers/oauth.py
OAuthLockKey ¶
Bases: NamedTuple
The (user, mcp, connector) triple an authorization is serialized under.
Source code in octomate/managers/oauth.py
OAuthManager ¶
Bases: Manager, Locks[OAuthLockKey]
Registered OAuth connectors bound to the current channel user.
Source code in octomate/managers/oauth.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
cipher
instance-attribute
¶
authorization_lifetime
instance-attribute
¶
register ¶
connector ¶
resolve_connector
async
¶
resolve_connector(
connector_id: str,
*,
user_id: UUID7,
mcp_id: UUID7 | None,
discovery_state: OAuthDiscoveryState | None = None,
) -> OAuthConnector
Source code in octomate/managers/oauth.py
start
async
¶
start(
user: User,
connector_id: str,
*,
mcp_id: UUID7 | None = None,
profile: UserProfile | None = None,
flow: OAuthFlowKind | None = None,
) -> OAuthStartResult
Source code in octomate/managers/oauth.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
pending_authorization
async
¶
pending_authorization(
user: User,
connector_id: str,
*,
profile: UserProfile | None = None,
mcp_id: UUID7 | None = None,
flow: OAuthFlowKind | None = None,
) -> OAuthStartResult | None
Restore a live authorization without starting another provider flow.
Source code in octomate/managers/oauth.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
complete_latest
async
¶
complete_latest(
user: User,
connector_id: str,
*,
mcp_id: UUID7 | None = None,
profile: UserProfile | None = None,
) -> OAuthGrant | OAuthPending
Poll this user's newest device operation from the originating context.
Source code in octomate/managers/oauth.py
complete
async
¶
complete(
user: User,
operation_id: UUID7,
*,
profile: UserProfile | None = None,
) -> OAuthGrant | OAuthPending
Complete a device operation owned by this user and originating profile.
Source code in octomate/managers/oauth.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
granted_connection ¶
granted_connection(
grant: OAuthGrant,
*,
user_id: UUID7,
connector_id: str,
existing: OAuthConnection | None,
flow: OAuthFlowKind,
mcp_id: UUID7 | None = None,
) -> OAuthConnection
This user's connection to a connector, carrying a grant, encrypted.
The one place credentials become storable, shared by every way of obtaining them — a device poll, a browser callback, a refresh — so replacement is one behaviour rather than three that drift. The whole token envelope is rewritten together: a refresh that kept half of the old one would leave a rotated refresh token pointing at a grant that no longer exists.
Touches no session. Persisting is the caller's, because only the caller knows what else has to land in the same transaction — consuming the operation that produced the grant has to commit with it or not at all.
Source code in octomate/managers/oauth.py
staged_authorization
async
¶
The provider request a UUID-only start link stands for.
Reading it is what keeps the provider's URI — client id, scopes, state, PKCE challenge — out of the message the user was sent, which carries nothing but this operation's id.
Source code in octomate/managers/oauth.py
complete_callback
async
¶
complete_callback(
connector_id: str,
*,
state: str,
code: str,
issuer: str | None = None,
) -> OAuthCallback
Finish an authorization-code operation from the provider's callback.
Nothing about this request proves who sent it — it is an ordinary browser GET arriving out of band — so everything binding it to a person was decided when the authorization started and is checked again here. The state matches an operation that has not been spent or expired; that operation names the profile that asked; and the profile still has to resolve to the same registered user, because a YAML declaration removed mid-flow must not finish as a connection.
Source code in octomate/managers/oauth.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
link_profile
async
¶
Link the verified channel account to the user who started OAuth.
Source code in octomate/managers/oauth.py
abandon_callback
async
¶
Close an operation the provider says the user turned down.
A denial is an answer, so the operation is spent rather than left to expire — otherwise the link the user declined stays live for its full lifetime.
Source code in octomate/managers/oauth.py
operation_for_state
async
¶
operation_for_state(
session: AsyncSession, connector_id: str, state: str
) -> tuple[
OAuthOperation, AuthorizationCodeOperationPayload
]
The live operation a callback's state belongs to, and its sealed payload.
The state's own prefix names the operation, since the row cannot be searched by a value stored encrypted; the comparison that follows is against the whole state, so naming an operation is not the same as being able to finish it.
Source code in octomate/managers/oauth.py
usable_operation ¶
Refuse an operation that is missing, another connector's, spent, or stale.
Source code in octomate/managers/oauth.py
authorization_payload ¶
Source code in octomate/managers/oauth.py
invalidate
async
¶
invalidate(
user: User,
connector_id: str,
*,
mcp_id: UUID7 | None = None,
expected_token: SecretStr | None = None,
) -> None
Record that this user's credentials for a connector no longer work.
Only the provider can say so — a revoked token answers 401 while nothing
about the stored row changed — so something that spoke to it has to bring
the news back. Marking it is what stops access_token handing the dead
credential out again, which is what turns a capability that can only fail
into an offer to authorize afresh.
Nothing to mark is a normal outcome: a second 401 from the same dead session finds it already recorded.
Source code in octomate/managers/oauth.py
connection_status
async
¶
connection_status(
user: User,
connector_id: str,
*,
mcp_id: UUID7 | None = None,
) -> OAuthConnectionStatus | None
Whether this user has a connection to a connector, and whether it works.
None is never having connected; "invalid" is having connected and lost
it. access_token collapses both to no token, which is right for using one
and wrong for explaining its absence — a user who was connected a moment ago
cannot see that they no longer are, and only this tells them apart.
Source code in octomate/managers/oauth.py
access_token
async
¶
Return this user's active connector token.
Source code in octomate/managers/oauth.py
refresh
async
¶
Spend this user's refresh token for a credential worth starting a run on.
Serialized, and re-read once the lock is held, because a rotating refresh token is spendable exactly once: two runs racing on the same near-expired connection would send the loser to the provider with a token the winner had already rotated, and the connection would die of being used correctly.
A provider that refuses the refresh has ended the connection, so it retires the same way a 401 does. A provider that merely failed to answer raises, because nothing about the credential was learned.
Source code in octomate/managers/oauth.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | |
expiring ¶
Whether a credential has too little life left to start a run on.
octomate.managers.spills ¶
The database-backed spill store for oversized tool output.
SpillStore
dataclass
¶
Bases: Manager
The tool-output-limits OverflowStore, backed by the Octomate database.
The harness ships only a local-file store, whose handles resolve against one
host's filesystem. A spill has to outlive the request that produced it — the
handle is what the model reads back through read_tool_result, possibly turns
later — and Octomate answers a conversation from whichever process picks the
message up. Sharing the database is what makes those the same payload.
Payloads are zlib-compressed. A spill is by definition the oversized end of what tools return, and that content is the compressible kind, so this is most of what keeps a blob column reasonable on SQLite.
Source code in octomate/managers/spills.py
write
async
¶
Persist data under key, returning it unchanged as the handle.
The key already encodes the run, the tool call, and the retry, so it is self-contained — nothing else is needed to find the row again.