OpenAPI令牌大小分析工具

用于分析和比较Stripe MCP服务器中OpenAPI规范令牌使用情况的工具,支持动态API响应和令牌计数。

  • by tomchen-stripe
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 tomchen-stripe/mcp-server-token-sizes

使用说明

MCP服务器OpenAPI令牌大小

标记有多少代币 三元刀具设计 因为Stripe面向用户的MCP服务器用完了。

在三元工具设计中,Stripe的API在MCP响应中动态返回给用户,而不是在用户连接到Stripe的MCP服务器时静态返回。

大约有572个Stripe API,176个是顶级API(2025年)。

所有响应都是从以下位置解析的 Stripe的OpenAPI规范.

我们使用GPT-4的tiktoken来编码令牌。

Metatool响应是使用此生成的 原型.

安装

pip install -e .

用法

python get_size.py <filename>

Stripe的OpenAPI规范令牌计数

  • spec3.json: 1218830
  • spec3.sdk.json: 1557620

Stripe mcp令牌使用情况

使用176进行基准测试* Stripe的572个API端点(占总API的30%)中的(顶级API)。

使用三元工具设计

list-api-endpoints, get-api-endpoint-schema, invoke-api-endpoint

列出api端点

  1. 仅返回所有工具名称
文件 令牌(176个api) 估计令牌(572个api)
响应/列出api端点/name-only.txt 903个代币 2709个代币
  1. 返回所有工具名称和描述
文件 令牌(176个api) 估计令牌(572个api)
responses/列出api端点/name-and-description.txt 4347个代币 13041个代币
  1. 返回相关工具名称/描述

估计我们是否要返回与用户试图做的事情相关的工具子集。这里有更多关于我们如何返回API子集的探索。

估计令牌(适用于大约十几个API)名称 估计令牌(用于大约十几个APIs)名称和描述
61个代币 297个代币
公共API端点增长(2020-2025)
年度 运营ID计数 同比增长 %变化
2025年(10月24日) 583 +21 +3.7%
2024年(12月24日) 562 +64 +12.9%
2023年(12月21日) 498 +54 +12.2%
2022年(12月23日) 444 +54 +13.8%
2021年(12月23日) 390 +28 +7.7%
2020年(12月15日) 362 基线 -

获取api端点模式

  1. 返回完整的OpenAPI模式
文件 令牌
PostProducts(P89模式大小) responses/get-api端点模式/full-openapi-schema.txt 2873个代币
PostCheckoutSessions(P100架构大小) responses/get-api端点模式/完整的postcheckoutsessions-schema.json 16413个代币

模型上下文大小(当前-2025)

模型 输入上下文窗口
GPT-5 400k
GPT-5迷你 400k
GPT-5纳米 400k
GPT-4.1 1047k
GPT-oss-120b 131k
GPT-oss-20b 131k
GPT-5聊天 128k
聊天GPT-4o 128k
claude-sonnet-4-5 200k
claude-haiku-4-5 20万
claude-opus-4-1 200k
双子座-2.5-pro 1048k
双子座2.5英尺 1048k

模型上下文大小(较旧)

模型 输入上下文窗口
GPT-4.1迷你版 1047k
GPT-4涡轮增压发动机 128k
GPT-3.5涡轮增压发动机 16k
GPT-4 8k
o1 200k
o3 200k
claude-sonnet-4-0 200k
claude-opus-4-0 200k
claude-3-5-haiku最新 200k
克劳德·海库3 200k
双子座-2.0闪光 1048k
双子座-2.0-flash-lite 1048k

OpenAI Anthropic 深度求索 光标

模型弃用时间表

Anthropic:平均1~1.5年 OpenAI:平均约1.5-3年

包括操作ID

Click to expand
DeleteAccountsAccount
DeleteCouponsCoupon
DeleteCustomersCustomer
DeleteEphemeralKeysKey
DeleteInvoiceitemsInvoiceitem
DeleteInvoicesInvoice
DeletePlansPlan
DeleteProductsId
DeleteSubscriptionItemsItem
DeleteSubscriptionsSubscriptionExposedId
DeleteTaxIdsId
DeleteWebhookEndpointsWebhookEndpoint
GetAccount
GetAccounts
GetAccountsAccount
GetApplicationFees
GetApplicationFeesId
GetBalance
GetBalanceSettings
GetBalanceTransactions
GetBalanceTransactionsId
GetCharges
GetChargesCharge
GetConfirmationTokensConfirmationToken
GetCountrySpecs
GetCountrySpecsCountry
GetCoupons
GetCouponsCoupon
GetCreditNotes
GetCreditNotesId
GetCustomers
GetCustomersCustomer
GetDisputes
GetDisputesDispute
GetEvents
GetEventsId
GetExchangeRates
GetExchangeRatesRateId
GetFileLinks
GetFileLinksLink
GetFiles
GetFilesFile
GetInvoicePayments
GetInvoicePaymentsInvoicePayment
GetInvoiceRenderingTemplates
GetInvoiceRenderingTemplatesTemplate
GetInvoiceitems
GetInvoiceitemsInvoiceitem
GetInvoices
GetInvoicesInvoice
GetLinkAccountSessionsSession
GetLinkedAccounts
GetLinkedAccountsAccount
GetMandatesMandate
GetPaymentIntents
GetPaymentIntentsIntent
GetPaymentLinks
GetPaymentLinksPaymentLink
GetPaymentMethodConfigurations
GetPaymentMethodConfigurationsConfiguration
GetPaymentMethodDomains
GetPaymentMethodDomainsPaymentMethodDomain
GetPaymentMethods
GetPaymentMethodsPaymentMethod
GetPayouts
GetPayoutsPayout
GetPlans
GetPlansPlan
GetPrices
GetPricesPrice
GetProducts
GetProductsId
GetPromotionCodes
GetPromotionCodesPromotionCode
GetQuotes
GetQuotesQuote
GetRefunds
GetRefundsRefund
GetReviews
GetReviewsReview
GetSetupAttempts
GetSetupIntents
GetSetupIntentsIntent
GetShippingRates
GetShippingRatesShippingRateToken
GetSourcesSource
GetSubscriptionItems
GetSubscriptionItemsItem
GetSubscriptionSchedules
GetSubscriptionSchedulesSchedule
GetSubscriptions
GetSubscriptionsSubscriptionExposedId
GetTaxCodes
GetTaxCodesId
GetTaxIds
GetTaxIdsId
GetTaxRates
GetTaxRatesTaxRate
GetTokensToken
GetTopups
GetTopupsTopup
GetTransfers
GetTransfersTransfer
GetWebhookEndpoints
GetWebhookEndpointsWebhookEndpoint
PostAccountLinks
PostAccountSessions
PostAccounts
PostAccountsAccount
PostBalanceSettings
PostCharges
PostChargesCharge
PostCoupons
PostCouponsCoupon
PostCreditNotes
PostCreditNotesId
PostCustomerSessions
PostCustomers
PostCustomersCustomer
PostDisputesDispute
PostEphemeralKeys
PostExternalAccountsId
PostFileLinks
PostFileLinksLink
PostFiles
PostInvoiceitems
PostInvoiceitemsInvoiceitem
PostInvoices
PostInvoicesInvoice
PostLinkAccountSessions
PostPaymentIntents
PostPaymentIntentsIntent
PostPaymentLinks
PostPaymentLinksPaymentLink
PostPaymentMethodConfigurations
PostPaymentMethodConfigurationsConfiguration
PostPaymentMethodDomains
PostPaymentMethodDomainsPaymentMethodDomain
PostPaymentMethods
PostPaymentMethodsPaymentMethod
PostPayouts
PostPayoutsPayout
PostPlans
PostPlansPlan
PostPrices
PostPricesPrice
PostProducts
PostProductsId
PostPromotionCodes
PostPromotionCodesPromotionCode
PostQuotes
PostQuotesQuote
PostRefunds
PostRefundsRefund
PostSetupIntents
PostSetupIntentsIntent
PostShippingRates
PostShippingRatesShippingRateToken
PostSources
PostSourcesSource
PostSubscriptionItems
PostSubscriptionItemsItem
PostSubscriptionSchedules
PostSubscriptionSchedulesSchedule
PostSubscriptions
PostSubscriptionsSubscriptionExposedId
PostTaxIds
PostTaxRates
PostTaxRatesTaxRate
PostTokens
PostTopups
PostTopupsTopup
PostTransfers
PostTransfersTransfer
PostWebhookEndpoints
PostWebhookEndpointsWebhookEndpoint

其他数据点

MCP动态工具之间的余弦距离

以下文件包含{operationId}:{description}条目:

data/spec3-top-level-name-description.json:176个顶级API工具名称+说明 data/spec3-top-level-name-description.json:所有572 API工具名称+说明

这 scripts/run_pipeline.py 嵌入上述文件中的条目、计算成对最近邻距离, 对它们进行聚类,然后计算聚类之间的距离。彼此靠近的集群 如果集群内靠近的工具或工具的余弦距离<=0.15,则将其标记为潜在模糊:

对于176个顶级API,有三个潜在的模糊集群:

  1. GetAccount,GetAccountsAccount
  2. GetPaymentMethods配置,GetPaymentMethod配置
  3. GetPaymentMethodDomains,GetPaymentMethodDomains支付方法域

第一个是别名,重复的API。第二个和第三个是列表与细节端点,自然会与用户提示区分开来,例如“显示我的支付配置”(列表)与“显示我我的支付设置”(细节)。

对于全572 API文件,有67个潜在的模糊聚类,分为以下几类:

  • 列表与详细端点
  • 财政部内部银行与外部银行
  • 别名/重复API

这些歧义可以通过用户写的自然提示来消除,例如“显示我的信用余额交易”(列表)与“显示我信用余额交易“(详细信息)。

Stripe MCP工具的尺寸(11/7/25)

retrieve_balance.json                             52 tokens
get_stripe_account_info.json                      54 tokens
finalize_invoice.json                            108 tokens
cancel_subscription.json                         111 tokens
list_coupons.json                                129 tokens
list_products.json                               135 tokens
create_product.json                              143 tokens
create_customer.json                             150 tokens
create_payment_link.json                         167 tokens
create_invoice.json                              170 tokens
list_invoices.json                               184 tokens
list_customers.json                              192 tokens
list_payment_intents.json                        204 tokens
list_prices.json                                 208 tokens
create_invoice_item.json                         220 tokens
create_refund.json                               248 tokens
list_disputes.json                               241 tokens
fetch_stripe_resources.json                      271 tokens
search_stripe_documentation.json                 292 tokens
list_subscriptions.json                          310 tokens
create_price.json                                412 tokens
update_dispute.json                              437 tokens
create_coupon.json                               514 tokens
update_subscription.json                         518 tokens
search_stripe_resources.json                    1494 tokens
-----------------------------------------------------------
TOTAL                                           6964 tokens

假设最小的令牌窗口容量(128K-ChatGPT5),我们消耗了5% 今天的上下文窗口。

如果我们用完了100%的上下文窗口,我们可以添加:

  • 81我们最大的工具
  • 435个我们的平均尺寸工具

如果我们使用了50%的上下文窗口,我们可以添加:

  • 40我们最大的工具
  • 117个我们的平均尺寸工具

如果我们使用了25%的上下文窗口,我们可以添加:

  • 我们最大的20个工具
  • 58我们的平均大小的工具

如果我们使用了10%的上下文窗口,我们可以添加:

  • 8我们最大的工具
  • 我们平均尺寸的43个工具

自 get_static_tools_sizes.py.