Skip to content

log character counts and estimated tokens #30

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

Merged
merged 4 commits into from
May 7, 2025

Conversation

Jephuff
Copy link
Contributor

@Jephuff Jephuff commented Apr 29, 2025

Logs the character size of each tool as it loads, logs the total character length of all tools and an estimate of the tokens (seems like ~4 characters is roughly a token, but will obviously vary)

Formatting I have right now, definitely open to suggestions to make it better

2025-04-29T19:33:04.100713Z  INFO mcp_apollo_server: Loading schema schema_path="supergraph.graphql"
2025-04-29T19:33:04.107599Z  INFO mcp_apollo_server::server: Loading operation operation_path="graphql/weather/operations/alerts.graphql"
2025-04-29T19:33:04.108761Z  INFO mcp_apollo_server::operations: Tool GetAlerts loaded with a character count of 754
2025-04-29T19:33:04.108793Z  INFO mcp_apollo_server::server: Loading operation operation_path="graphql/weather/operations/all.graphql"
2025-04-29T19:33:04.109415Z  INFO mcp_apollo_server::operations: Tool GetAllWeatherData loaded with a character count of 1489
2025-04-29T19:33:04.109429Z  INFO mcp_apollo_server::server: Loading operation operation_path="graphql/weather/operations/forecast.graphql"
2025-04-29T19:33:04.109708Z  INFO mcp_apollo_server::operations: Tool GetForecast loaded with a character count of 801
2025-04-29T19:33:04.109723Z  INFO mcp_apollo_server::server: Size of tools:
2025-04-29T19:33:04.109727Z  INFO mcp_apollo_server::server:     characters: 3044
2025-04-29T19:33:04.109730Z  INFO mcp_apollo_server::server:     estimated tokens: 761
2025-04-29T19:33:04.109892Z  INFO mcp_apollo_server: Starting MCP server in stdio mode

@Jephuff Jephuff force-pushed the jeffrey/log-character-length branch from b4dc8d4 to a925a35 Compare April 29, 2025 19:34
@Jephuff Jephuff force-pushed the jeffrey/log-character-length branch from a925a35 to 64e9e3d Compare May 1, 2025 23:49
@Jephuff Jephuff requested a review from pubmodmatt May 2, 2025 15:11
"Tool {} loaded with a character count of {}. Estimated tokens: {}",
operation_name,
length,
length / 4
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it dividing by 4 here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I found it here - "For Claude, a token approximately represents 3.5 English characters". If that's the case, let's get a comment in here explaining the computation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, 4 was the magical number that everyone seems to say is a reasonable estimate across models. I'll add a comment 👍

@Jephuff Jephuff requested a review from pubmodmatt May 7, 2025 21:49
@Jephuff Jephuff merged commit 8614f2d into main May 7, 2025
5 checks passed
@Jephuff Jephuff deleted the jeffrey/log-character-length branch May 7, 2025 22:06
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