-
Notifications
You must be signed in to change notification settings - Fork 0
feat: download contract API #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adith-dinesh
wants to merge
1
commit into
main
Choose a base branch
from
feature/download-contract-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Tool } from '@modelcontextprotocol/sdk/types.js'; | ||
import { SpotDraftClient } from '../spotdraft_client.js'; | ||
|
||
const getContractDownloadTool: Tool = { | ||
name: 'get_contract_download', | ||
description: `Downloads a copy of the contract file directly from SpotDraft using API v2.1. | ||
|
||
Returns the contract file as base64-encoded data along with metadata such as filename and content type. | ||
|
||
## Parameters | ||
- \`composite_id\`: ID of the Contract. Should be of the form T-123 or H-123. T stands for Template contracts and H stands for Historical contracts. | ||
|
||
## Response | ||
Returns an object containing: | ||
- \`data\`: Base64-encoded file content | ||
- \`filename\`: Original filename (if available from response headers) | ||
- \`contentType\`: MIME type of the file (if available from response headers) | ||
|
||
### How the Model Should Use the Output | ||
The \`data\` field contains the raw binary content of the contract file. To help the user: | ||
- If the platform supports file uploads (e.g., Slack, email, chat app), use \`data\`, \`filename\`, and \`contentType\` to send the contract as a file attachment. | ||
- If direct file sharing is not supported, respond with a message indicating the file was downloaded and provide its name and type. | ||
- Do not attempt to display or summarize the file content. | ||
- Do not try to decode or transform the binary string. | ||
|
||
### Usage Example | ||
Given \`composite_id = "T-332728"\`, the model can call this tool to retrieve and forward the finalized contract to the user as a downloadable file.`, | ||
|
||
inputSchema: { | ||
type: 'object', | ||
properties: { | ||
composite_id: { | ||
type: 'string', | ||
description: | ||
'ID of the Contract (e.g., T-123 or H-123). T stands for Template contracts and H stands for Historical contracts.', | ||
}, | ||
}, | ||
required: ['composite_id'], | ||
}, | ||
}; | ||
|
||
interface GetContractDownloadRequest { | ||
composite_id: string; | ||
} | ||
|
||
const getContractDownload = async ( | ||
request: GetContractDownloadRequest, | ||
spotdraftClient: SpotDraftClient, | ||
): Promise<{ data: string; filename?: string; contentType?: string }> => { | ||
const endpoint = `/v2.1/public/contracts/${request.composite_id}/download`; | ||
return spotdraftClient.downloadFile(endpoint); | ||
}; | ||
|
||
export { getContractDownload, GetContractDownloadRequest, getContractDownloadTool }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix critical logic error in downloadFile method.
The method calls
this.post(endpoint, {})
which returns a parsed JSON response, but then tries to checkresponse.ok
on that result. Thepost()
method already handles response validation and returns the parsed response body, not the raw Response object.📝 Committable suggestion
🤖 Prompt for AI Agents